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

2018-03-27 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris created this revision.
dberris added reviewers: echristo, kpw, eizan, pelikan.

This change addresses http://llvm.org/PR36926 by allowing users to pick
which instrumentation bundles to use, when instrumenting with XRay. In
particular, the flag `-fxray-instrumentation-bundle=` has four valid
values:

- `all`: the default, which will emit all kinds of instrumentation

points.

- `none`: equivalent to -fnoxray-instrument
- `function-extents`: only emits the entry/exit sleds
- `custom-only`: only emits the custom event sleds


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/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,14 @@
+// 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
+
+// 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)
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -446,6 +446,21 @@
   }
 }
 
+static CodeGenOptions::XRayInstrumentationPointBundle
+parseXRayInstrumentationBundle(Arg *A, ArgList , DiagnosticsEngine ) {
+  StringRef V = A->getValue();
+  if (V == "all")
+return CodeGenOptions::XRayInstrumentationPointBundle::XRay_All;
+  if (V == "none")
+return CodeGenOptions::XRayInstrumentationPointBundle::XRay_None;
+  if (V == "function-extents")
+return CodeGenOptions::XRayInstrumentationPointBundle::XRay_FunctionExtents;
+  if (V == "custom-only")
+return CodeGenOptions::XRayInstrumentationPointBundle::XRay_CustomOnly;
+  D.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << V;
+  return CodeGenOptions::XRayInstrumentationPointBundle::XRay_All;
+}
+
 // Set the profile kind for fprofile-instrument.
 static void setPGOInstrumentor(CodeGenOptions , ArgList ,
DiagnosticsEngine ) {
@@ -853,6 +868,11 @@
   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 , const ArgList ) {
@@ -50,13 +52,14 @@
 << (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::err_drv_clang_unsupported)
+<< (std::string(XRayInstrumentOption) + " on " + Triple.str());
+  }
 } else {
   D.Diag(diag::err_drv_clang_unsupported)
-  << (std::string(XRayInstrumentOption) + " on non-supported target OS");
+  << (std::string(XRayInstrumentOption) +
+  " on non-supported target OS");
 }
 XRayInstrument = true;
 if (const Arg *A =
@@ -75,6 +78,19 @@
  options::OPT_fnoxray_always_emit_customevents, false))
   XRayAlwaysEmitCustomEvents = true;
 
+// We check the bundle of instrumentation that we let users choose. This
+  

[PATCH] D44888: [RISCV] Default enable linker relaxation and add -mrelax, -mno-relax flags

2018-03-27 Thread Shiva Chen via Phabricator via cfe-commits
shiva0217 updated this revision to Diff 140038.
shiva0217 retitled this revision from "[RISCV] Default enable linker relaxation 
and add -mno-relax flag to disable it" to "[RISCV] Default enable linker 
relaxation and add -mrelax, -mno-relax flags".
shiva0217 edited the summary of this revision.
shiva0217 added a comment.

Update patch to address Ana's comments.


Repository:
  rC Clang

https://reviews.llvm.org/D44888

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Arch/RISCV.cpp


Index: lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- lib/Driver/ToolChains/Arch/RISCV.cpp
+++ lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -14,6 +14,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
+#include "ToolChains/CommonArgs.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -51,6 +52,19 @@
   }
 }
   }
+
+  // -mrelax is default, unless -mno-relax is specified.
+  bool Relax = true;
+  if (auto *A = Args.getLastArg(options::OPT_mrelax, options::OPT_mno_relax))
+if (A->getOption().matches(options::OPT_mno_relax))
+  Relax = false;
+
+  if (Relax)
+Features.push_back("+relax");
+
+  // Now add any that the user explicitly requested on the command line,
+  // which may override the defaults.
+  handleTargetFeaturesGroup(Args, Features, 
options::OPT_m_riscv_Features_Group);
 }
 
 StringRef riscv::getRISCVABI(const ArgList , const llvm::Triple ) {
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -150,6 +150,9 @@
 def m_x86_Features_Group : OptionGroup<"">,
Group, Flags<[CoreOption]>, DocName<"X86">;
 
+def m_riscv_Features_Group : OptionGroup<"">,
+ Group, DocName<"RISCV">;
+
 def m_libc_Group : OptionGroup<"">, Group,
Flags<[HelpHidden]>;
 
@@ -1873,6 +1876,11 @@
 def meabi : Separate<["-"], "meabi">, Group, Flags<[CC1Option]>,
   HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, 
Values<"default,4,5,gnu">;
 
+def mrelax : Flag<["-"], "mrelax">,
+Group;
+def mno_relax : Flag<["-"], "mno-relax">,
+Group;
+
 def mno_constant_cfstrings : Flag<["-"], "mno-constant-cfstrings">, 
Group;
 def mno_global_merge : Flag<["-"], "mno-global-merge">, Group, 
Flags<[CC1Option]>,
   HelpText<"Disable merging of globals">;


Index: lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- lib/Driver/ToolChains/Arch/RISCV.cpp
+++ lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -14,6 +14,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
+#include "ToolChains/CommonArgs.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -51,6 +52,19 @@
   }
 }
   }
+
+  // -mrelax is default, unless -mno-relax is specified.
+  bool Relax = true;
+  if (auto *A = Args.getLastArg(options::OPT_mrelax, options::OPT_mno_relax))
+if (A->getOption().matches(options::OPT_mno_relax))
+  Relax = false;
+
+  if (Relax)
+Features.push_back("+relax");
+
+  // Now add any that the user explicitly requested on the command line,
+  // which may override the defaults.
+  handleTargetFeaturesGroup(Args, Features, options::OPT_m_riscv_Features_Group);
 }
 
 StringRef riscv::getRISCVABI(const ArgList , const llvm::Triple ) {
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -150,6 +150,9 @@
 def m_x86_Features_Group : OptionGroup<"">,
Group, Flags<[CoreOption]>, DocName<"X86">;
 
+def m_riscv_Features_Group : OptionGroup<"">,
+ Group, DocName<"RISCV">;
+
 def m_libc_Group : OptionGroup<"">, Group,
Flags<[HelpHidden]>;
 
@@ -1873,6 +1876,11 @@
 def meabi : Separate<["-"], "meabi">, Group, Flags<[CC1Option]>,
   HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, Values<"default,4,5,gnu">;
 
+def mrelax : Flag<["-"], "mrelax">,
+Group;
+def mno_relax : Flag<["-"], "mno-relax">,
+Group;
+
 def mno_constant_cfstrings : Flag<["-"], "mno-constant-cfstrings">, Group;
 def mno_global_merge : Flag<["-"], "mno-global-merge">, Group, Flags<[CC1Option]>,
   HelpText<"Disable merging of globals">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328688 - Fix some handling of AST nodes with diagnostics.

2018-03-27 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Tue Mar 27 21:16:13 2018
New Revision: 328688

URL: http://llvm.org/viewvc/llvm-project?rev=328688=rev
Log:
Fix some handling of AST nodes with diagnostics.

The diagnostic system for Clang can already handle many AST nodes.  Instead
of converting them to strings first, just hand the AST node directly to
the diagnostic system and let it handle the output.  Minor changes in some
diagnostic output.


Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/lib/Sema/SemaCUDA.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/Preprocessor/has_include.c
cfe/trunk/test/Sema/warn-duplicate-enum.c
cfe/trunk/test/SemaCUDA/function-overload.cu
cfe/trunk/test/SemaCUDA/kernel-call.cu
cfe/trunk/test/SemaCXX/ms-interface.cpp
cfe/trunk/test/SemaCXX/typo-correction.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
cfe/trunk/test/SemaObjC/comptypes-legal.m
cfe/trunk/test/SemaObjC/protocol-expr-neg-1.m
cfe/trunk/test/SemaTemplate/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=328688=328687=328688=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Mar 27 21:16:13 
2018
@@ -575,7 +575,7 @@ def err_cxx11_attribute_forbids_argument
 def err_attribute_requires_arguments : Error<
   "parentheses must be omitted if %0 attribute's argument list is empty">;
 def err_cxx11_attribute_forbids_ellipsis : Error<
-  "attribute '%0' cannot be used as an attribute pack">;
+  "attribute %0 cannot be used as an attribute pack">;
 def err_cxx11_attribute_repeated : Error<
   "attribute %0 cannot appear multiple times in an attribute specifier">;
 def warn_cxx14_compat_using_attribute_ns : Warning<

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=328688=328687=328688=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 27 21:16:13 
2018
@@ -1329,7 +1329,7 @@ def err_invalid_member_in_interface : Er
   "nested class }0%1 is not permitted within an interface type">;
 def err_invalid_base_in_interface : Error<
   "interface type cannot inherit from "
-  "%select{'struct|non-public 'interface|'class}0 %1'">;
+  "%select{struct|non-public interface|class}0 %1">;
 
 def err_abstract_type_in_decl : Error<
   "%select{return|parameter|variable|field|instance variable|"
@@ -1629,7 +1629,7 @@ def err_missing_default_ctor : Error<
   "%select{base class|member}2 %3 %select{which|which|of %1}0 "
   "does not have a default constructor">;
 def note_due_to_dllexported_class : Note<
-  "due to '%0' being dllexported%select{|; try compiling in C++11 mode}1">;
+  "due to %0 being dllexported%select{|; try compiling in C++11 mode}1">;
 
 def err_illegal_union_or_anon_struct_member : Error<
   "%select{anonymous struct|union}0 member %1 has a non-trivial "
@@ -2986,11 +2986,11 @@ def warn_lock_exclusive_and_shared : War
 def note_lock_exclusive_and_shared : Note<
   "the other acquisition of %0 '%1' is here">;
 def warn_variable_requires_any_lock : Warning<
-  "%select{reading|writing}1 variable '%0' requires holding "
+  "%select{reading|writing}1 variable %0 requires holding "
   "%select{any mutex|any mutex exclusively}1">,
   InGroup, DefaultIgnore;
 def warn_var_deref_requires_any_lock : Warning<
-  "%select{reading|writing}1 the value pointed to by '%0' requires holding "
+  "%select{reading|writing}1 the value pointed to by %0 requires holding "
   "%select{any mutex|any mutex exclusively}1">,
   InGroup, DefaultIgnore;
 def warn_fun_excludes_mutex : Warning<
@@ -3014,25 +3014,25 @@ def warn_acquire_requires_negative_cap :
 
 // Thread safety warnings on pass by reference
 def warn_guarded_pass_by_reference : Warning<
-  "passing variable '%1' by reference requires holding %0 "
+  "passing variable %1 by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
   InGroup, DefaultIgnore;
 def warn_pt_guarded_pass_by_reference : Warning<
-  "passing the value that '%1' points to by reference requires holding %0 "
+  "passing the value that %1 points to by reference requires holding %0 "
   "%select{'%2'|'%2' 

[PATCH] D44968: [ObjC] Generalize NRVO to cover non-trivial C structs

2018-03-27 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Is it possible to just do this for all structs?  I don't think it hurts 
anything to do it for structs that are trivial and returned indirectly, and it 
would certainly be nice to construct C return values in-place even if they're 
guilty of nothing more than being, y'know, really really big.




Comment at: lib/CodeGen/CGDecl.cpp:1116
   if (const RecordType *RecordTy = Ty->getAs()) {
-if (!cast(RecordTy->getDecl())->hasTrivialDestructor()) 
{
+const auto *RD = cast(RecordTy->getDecl());
+const auto *CXXRD = dyn_cast(RD);

I think this cast isn't necessary.


Repository:
  rC Clang

https://reviews.llvm.org/D44968



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


[PATCH] D44968: [ObjC] Generalize NRVO to cover non-trivial C structs

2018-03-27 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added reviewers: rjmccall, doug.gregor, rsmith.

r326307 and r327870 made changes that allowed using non-trivial C
structs with fields qualified with __strong or __weak. This commit generalizes 
NRVO, which could only be applied to C++ structs, to cover non-trivial C 
structs.


Repository:
  rC Clang

https://reviews.llvm.org/D44968

Files:
  lib/CodeGen/CGDecl.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaStmt.cpp
  test/CodeGenObjC/objc-non-trivial-struct-nrvo.m

Index: test/CodeGenObjC/objc-non-trivial-struct-nrvo.m
===
--- /dev/null
+++ test/CodeGenObjC/objc-non-trivial-struct-nrvo.m
@@ -0,0 +1,111 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck %s
+
+// CHECK: %[[STRUCT_TRIVIAL:.*]] = type { i32 }
+// CHECK: %[[STRUCT_STRONG:.*]] = type { i8* }
+// CHECK: %[[STRUCT_WEAK:.*]] = type { i8* }
+
+typedef struct {
+  int x;
+} Trivial;
+
+typedef struct {
+  id x;
+} Strong;
+
+typedef struct {
+  __weak id x;
+} Weak;
+
+// CHECK: define i32 @testTrivial()
+// CHECK-NOT: br
+// CHECK: ret i32 %{{.*}}
+
+Trivial testTrivial() {
+  Trivial a;
+  return a;
+}
+
+// CHECK: define i8* @testStrong()
+// CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_STRONG]], align 8
+// CHECK: %[[NRVO:.*]] = alloca i1, align 1
+// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONG]]* %[[RETVAL]] to i8**
+// CHECK: call void @__default_constructor_8_s0(i8** %[[V0]])
+// CHECK: store i1 true, i1* %[[NRVO]], align 1
+// CHECK: %[[NRVO_VAL:.*]] = load i1, i1* %[[NRVO]], align 1
+// CHECK: br i1 %[[NRVO_VAL]],
+
+// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONG]]* %[[RETVAL]] to i8**
+// CHECK: call void @__destructor_8_s0(i8** %[[V1]])
+// CHECK: br
+
+// CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[RETVAL]], i32 0, i32 0
+// CHECK: %[[V2:.*]] = load i8*, i8** %[[COERCE_DIVE]], align 8
+// CHECK: ret i8* %[[V2]]
+
+Strong testStrong() {
+  Strong a;
+  return a;
+}
+
+// CHECK: define void @testWeak(%[[STRUCT_WEAK]]* noalias sret %[[AGG_RESULT:.*]])
+// CHECK: %[[NRVO:.*]] = alloca i1, align 1
+// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_RESULT]] to i8**
+// CHECK: call void @__default_constructor_8_w0(i8** %[[V0]])
+// CHECK: store i1 true, i1* %[[NRVO]], align 1
+// CHECK: %[[NRVO_VAL:.*]] = load i1, i1* %[[NRVO]], align 1
+// CHECK: br i1 %[[NRVO_VAL]],
+
+// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_RESULT]] to i8**
+// CHECK: call void @__destructor_8_w0(i8** %[[V1]]) #3
+// CHECK: br
+
+// CHECK-NOT: call
+// CHECK: ret void
+
+Weak testWeak() {
+  Weak a;
+  return a;
+}
+
+// CHECK: define void @testWeak2(
+// CHECK: call void @__default_constructor_8_w0(
+// CHECK: call void @__default_constructor_8_w0(
+// CHECK: call void @__copy_constructor_8_8_w0(
+// CHECK: call void @__copy_constructor_8_8_w0(
+// CHECK: call void @__destructor_8_w0(
+// CHECK: call void @__destructor_8_w0(
+
+Weak testWeak2(int c) {
+  Weak a, b;
+  if (c)
+return a;
+  else
+return b;
+}
+
+// CHECK: define internal void @"\01-[C1 foo1]"(%[[STRUCT_WEAK]]* noalias sret %[[AGG_RESULT:.*]], %{{.*}}* %{{.*}}, i8* %{{.*}})
+// CHECK: %[[NRVO:.*]] = alloca i1, align 1
+// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_RESULT]] to i8**
+// CHECK: call void @__default_constructor_8_w0(i8** %[[V0]])
+// CHECK: store i1 true, i1* %[[NRVO]], align 1
+// CHECK: %[[NRVO_VAL:.*]] = load i1, i1* %[[NRVO]], align 1
+// CHECK: br i1 %[[NRVO_VAL]],
+
+// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_RESULT]] to i8**
+// CHECK: call void @__destructor_8_w0(i8** %[[V1]])
+// CHECK: br
+
+// CHECK-NOT: call
+// CHECK: ret void
+
+__attribute__((objc_root_class))
+@interface C1
+- (Weak)foo1;
+@end
+
+@implementation C1
+- (Weak)foo1 {
+  Weak a;
+  return a;
+}
+@end
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -2872,7 +2872,7 @@
 /// NRVO, or NULL if there is no such candidate.
 VarDecl *Sema::getCopyElisionCandidate(QualType ReturnType, Expr *E,
CopyElisionSemanticsKind CESK) {
-  if (!getLangOpts().CPlusPlus)
+  if (!getLangOpts().CPlusPlus && !ReturnType.isNonTrivialToPrimitiveCopy())
 return nullptr;
 
   // - in a return statement in a function [where] ...
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12712,8 +12712,10 @@
   // Try to apply the named return value optimization. We have to check
   // if we can do this here because lambdas keep return statements around
   // to deduce an implicit return type.
-  if (getLangOpts().CPlusPlus && FD->getReturnType()->isRecordType() &&
-  !FD->isDependentContext())
+  QualType RetTy = 

[PATCH] D43764: [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting.

2018-03-27 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: 
clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h:75
+/// \brief Deduplicate, check for conflicts, and convert all Replacements 
stored
+/// in \c TUs to AtomicChange. If conflicts occur, no Replacements are applied.
 ///

jdemeule wrote:
> ioeric wrote:
> > ` If conflicts occur, no Replacements are applied.` This doesn't seem to be 
> > accurate; non-conflicting replacements are still added.
> You are perfectly right the description does not match the behavior.
> 
> I think I will update this part to //"Deduplicate, check for conflicts, and 
> convert all Replacements stored in TUs to a single AtomicChange per file. 
> Conflicting replacement are skipped. However, the order of converting 
> Replacements extracted from TUs and TUDs to AtomicChange is undefined."//
> 
> And amend `FileChanges` with //"Only non conflicting replacements are kept 
> into FileChanges."//
> a single AtomicChange per file
As `FileChanges` are a `FileToChangesMap`, it's already clear that it's a set 
of changes per file. We don't want to say "single AtomicChange" here because 
this is just an implementation details. 



Comment at: clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp:179
+  // To keep current clang-apply-replacement behavior, report conflicting
+  // replacements skip file containing conflicts, all replacements are stored
+  // into 1 big AtomicChange.

jdemeule wrote:
> ioeric wrote:
> > I think we are only skipping conflicts; non-conflicting replacements are 
> > still added even if the file contains other conflicts?
> > 
> > This doesn't seem to have caused any problem because the current caller 
> > simply drops all changes if conflict is detected in any file, but we should 
> > still make it clear what the behavior of `mergeAndDeduplicate` is (in the 
> > API doc) e.g.  what would `FileChanges` contain if there is conflict in 
> > some but not all files?
> I will update this comment to:
> //"To keep current clang-apply-replacement behavior, report conflicting 
> replacements on corresponding file, all replacements are stored into 1 big 
> AtomicChange."//
I would drop the "To keep the current behavior" part because it's only relevant 
in code review. Future readers wouldn't know what the "current" behavior is. 


https://reviews.llvm.org/D43764



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


[PATCH] D44865: [libc++] Implement P0608R1 - A sane variant converting constructor

2018-03-27 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 140029.
lichray added a comment.

Macro-free


Repository:
  rCXX libc++

https://reviews.llvm.org/D44865

Files:
  include/variant
  test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
  test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp

Index: test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
===
--- test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
+++ test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_convertible.hpp"
 #include "test_macros.h"
@@ -53,7 +54,7 @@
 
 void test_T_ctor_sfinae() {
   {
-using V = std::variant;
+using V = std::variant;
 static_assert(!std::is_constructible::value, "ambiguous");
   }
   {
@@ -66,6 +67,16 @@
   "no matching constructor");
   }
   {
+using V = std::variant;
+static_assert(!std::is_constructible::value,
+  "no matching constructor");
+  }
+  {
+using V = std::variant;
+static_assert(!std::is_constructible::value,
+  "no explicit bool in constructor");
+  }
+  {
 using V = std::variant;
 static_assert(
 !std::is_constructible::value,
@@ -99,6 +110,21 @@
 static_assert(v.index() == 1, "");
 static_assert(std::get<1>(v) == 42, "");
   }
+  {
+constexpr std::variant v(42);
+static_assert(v.index() == 1, "");
+static_assert(std::get<1>(v) == 42, "");
+  }
+  {
+std::variant v = "foo";
+assert(v.index() == 0);
+assert(std::get<0>(v) == "foo");
+  }
+  {
+std::variant> v = nullptr;
+assert(v.index() == 1);
+assert(std::get<1>(v) == nullptr);
+  }
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
 using V = std::variant;
Index: test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
===
--- test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
+++ test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 #include "variant_test_helpers.hpp"
@@ -128,7 +129,7 @@
 
 void test_T_assignment_sfinae() {
   {
-using V = std::variant;
+using V = std::variant;
 static_assert(!std::is_assignable::value, "ambiguous");
   }
   {
@@ -139,6 +140,15 @@
 using V = std::variant;
 static_assert(!std::is_assignable::value, "no matching operator=");
   }
+  {
+using V = std::variant;
+static_assert(!std::is_assignable::value, "no matching operator=");
+  }
+  {
+using V = std::variant;
+static_assert(!std::is_assignable::value,
+  "no explicit bool in operator=");
+  }
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
 using V = std::variant;
@@ -167,6 +177,33 @@
 assert(v.index() == 1);
 assert(std::get<1>(v) == 43);
   }
+  {
+std::variant v;
+v = 42;
+assert(v.index() == 1);
+assert(std::get<1>(v) == 42);
+v = 43u;
+assert(v.index() == 0);
+assert(std::get<0>(v) == 43);
+  }
+  {
+std::variant v = true;
+v = std::false_type();
+assert(v.index() == 1);
+assert(std::get<1>(v) == false);
+v = "bar";
+assert(v.index() == 0);
+assert(std::get<0>(v) == "bar");
+  }
+  {
+std::variant v;
+v = nullptr;
+assert(v.index() == 1);
+assert(std::get<1>(v) == nullptr);
+v = std::true_type();
+assert(v.index() == 0);
+assert(std::get<0>(v));
+  }
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
 using V = std::variant;
Index: include/variant
===
--- include/variant
+++ include/variant
@@ -1097,11 +1097,40 @@
 template 
 struct __overload<_Tp, _Types...> : __overload<_Types...> {
   using __overload<_Types...>::operator();
-  __identity<_Tp> operator()(_Tp) const;
+
+  template 
+  auto operator()(_Tp, _Up&& __t) const
+  -> decltype(_Tp{__t}, __identity<_Tp>());
+};
+
+template 
+struct __overload_bool : _Base {
+  using _Base::operator();
+
+  template >
+  auto operator()(bool, _Up&&, int _Ap::* = 0) const -> __identity<_Tp>;
+
+  template >
+  auto operator()(bool, _Up&&) const
+  -> enable_if_t, __identity<_Tp>>;
 };
 
+template 
+struct __overload
+: __overload_bool<__overload<_Types...>, bool> {};
+template 
+struct __overload
+ 

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

2018-03-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: include/clang/Sema/Sema.h:3827
   bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
-  bool AllowParamOrMoveConstructible);
+  CopyElisionSemanticsKind CESK);
 

Quuxplusone wrote:
> Q: Is it appropriate for me to be changing the signature of this public 
> method at all? I don't know libclang's rules regarding this kind of change.
For reference, changes here are fine. We provide no API or ABI stability 
guarantees for our C++ ABI; libclang provides an ABI-stable C ABI layered on 
top of our internal API for this reason.



Comment at: include/clang/Sema/Sema.h:3806
 CES_Default = (CES_AllowParameters | CES_AllowDifferentTypes),
+CES_AsIfByStdMove = (CES_AllowParameters | CES_AllowDifferentTypes | 
CES_AllowExceptionVariables),
   };

Please wrap to 80 columns.



Comment at: lib/Sema/SemaStmt.cpp:3075-3076
+  } else {
+// The most common case for this is returning T from a function that
+// returns Expected. This is totally fine in a post-CWG1579 world,
+// but was not fine before.

I've seen this a lot more for returning `unique_ptr` from a function 
with return type `unique_ptr`. Maybe just give this `Expected` case as 
an example rather than saying it's the most common example?


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] D44921: [PowerPC] Option for secure plt mode

2018-03-27 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

I'll let Justin give the actual ACK, but this looks fine to me. The only 
question that I have (since I don't know anything about secure PLT) is whether 
this is a PPC-specific thing (since the option is a PPC option).




Comment at: include/clang/Driver/Options.td:1941
 def mno_vsx : Flag<["-"], "mno-vsx">, Group;
+def msecure_plt : Flag<["-"], "msecure-plt">, Group;
 def mpower8_vector : Flag<["-"], "mpower8-vector">,

Do we not want the negated option?



Comment at: lib/Driver/ToolChains/Arch/PPC.cpp:116
+ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver , const ArgList 
) {
+  ppc::ReadGOTPtrMode ReadGOT = ppc::ReadGOTPtrMode::Bss;
+  if (Args.getLastArg(options::OPT_msecure_plt))

Just a style question out of curiosity. Why the temporary? Since there are just 
two possible values, why not just return the respective enumerator?


https://reviews.llvm.org/D44921



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


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-27 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added inline comments.



Comment at: lib/CodeGen/CGCXXABI.h:610
 
+struct CatchRetScope final : EHScopeStack::Cleanup {
+  llvm::CatchPadInst *CPI;

Should be `public`?



Comment at: lib/CodeGen/CGCleanup.h:630
   static const EHPersonality MSVC_CxxFrameHandler3;
+  static const EHPersonality GNU_Wasm_CPlusCPlus;
 

We might consider having 2 personalities: one for use with builtin exceptions, 
and other for emulated exceptions? I'm imagining that with this style of IR we 
might be able to do emulated exceptions better than we have for emscripten 
today. We don't have to think about that now, but maybe the name of the 
personality might reflect it: e.g. `GNU_Wasm_CPlusPlus_Native` (or builtin) vs 
`GNU_Wasm_CPlusPlus_Emulated` (or external).



Comment at: lib/CodeGen/CGException.cpp:1236
+  // them, we should unwind to the next EH enclosing scope. We generate a call
+  // to rethrow function here to do that.
+  if (EHPersonality::get(*this).isWasmPersonality() && !HasCatchAll) {

Why do we need to call `__cxa_rethrow` instead of just emitting a rethrow 
instruction intrinsic to unwind?



Comment at: lib/CodeGen/CGException.cpp:1534
+  // In case of wasm personality, we need to pass the exception value to
+  // __clang_call_terminate function.
+  if (getLangOpts().CPlusPlus &&

Why?


Repository:
  rC Clang

https://reviews.llvm.org/D44931



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


[PATCH] D44913: [ObjC] Enable using C++ triviality type traits for non-trivial C structs

2018-03-27 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328680: [ObjC] Make C++ triviality type traits available to 
non-trivial C (authored by ahatanak, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44913?vs=139862=140023#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44913

Files:
  cfe/trunk/include/clang/Basic/TokenKinds.def
  cfe/trunk/lib/Sema/SemaExprCXX.cpp
  cfe/trunk/test/SemaObjC/non-trivial-struct-traits.m

Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -4513,6 +4513,8 @@
 // does not correctly compute triviality in the presence of multiple special
 // members of the same kind. Revisit this once the g++ bug is fixed.
   case UTT_HasTrivialDefaultConstructor:
+if (T.isNonTrivialToPrimitiveDefaultInitialize())
+  return false;
 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
 //   If __is_pod (type) is true then the trait is true, else if type is
 //   a cv class or union type (or array thereof) with a trivial default
@@ -4524,6 +4526,8 @@
  !RD->hasNonTrivialDefaultConstructor();
 return false;
   case UTT_HasTrivialMoveConstructor:
+if (T.isNonTrivialToPrimitiveDestructiveMove())
+  return false;
 //  This trait is implemented by MSVC 2012 and needed to parse the
 //  standard library headers. Specifically this is used as the logic
 //  behind std::is_trivially_move_constructible (20.9.4.3).
@@ -4533,6 +4537,8 @@
   return RD->hasTrivialMoveConstructor() && !RD->hasNonTrivialMoveConstructor();
 return false;
   case UTT_HasTrivialCopy:
+if (T.isNonTrivialToPrimitiveCopy())
+  return false;
 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
 //   If __is_pod (type) is true or type is a reference type then
 //   the trait is true, else if type is a cv class or union type
@@ -4545,6 +4551,8 @@
  !RD->hasNonTrivialCopyConstructor();
 return false;
   case UTT_HasTrivialMoveAssign:
+if (T.isNonTrivialToPrimitiveDestructiveMove())
+  return false;
 //  This trait is implemented by MSVC 2012 and needed to parse the
 //  standard library headers. Specifically it is used as the logic
 //  behind std::is_trivially_move_assignable (20.9.4.3)
@@ -4554,6 +4562,8 @@
   return RD->hasTrivialMoveAssignment() && !RD->hasNonTrivialMoveAssignment();
 return false;
   case UTT_HasTrivialAssign:
+if (T.isNonTrivialToPrimitiveCopy())
+  return false;
 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
 //   If type is const qualified or is a reference type then the
 //   trait is false. Otherwise if __is_pod (type) is true then the
@@ -4624,6 +4634,8 @@
 return true;
 
   case UTT_HasTrivialDestructor:
+if (T.isDestructedType() == QualType::DK_nontrivial_c_struct)
+  return false;
 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html
 //   If __is_pod (type) is true or type is a reference type
 //   then the trait is true, else if type is a cv class or union
Index: cfe/trunk/include/clang/Basic/TokenKinds.def
===
--- cfe/trunk/include/clang/Basic/TokenKinds.def
+++ cfe/trunk/include/clang/Basic/TokenKinds.def
@@ -433,12 +433,12 @@
 TYPE_TRAIT_1(__has_nothrow_move_assign, HasNothrowMoveAssign, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_constructor, HasNothrowConstructor, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_assign, HasTrivialAssign, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_move_assign, HasTrivialMoveAssign, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_copy, HasTrivialCopy, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_constructor, HasTrivialDefaultConstructor, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_destructor, HasTrivialDestructor, KEYCXX)
+TYPE_TRAIT_1(__has_trivial_assign, HasTrivialAssign, KEYALL)
+TYPE_TRAIT_1(__has_trivial_move_assign, HasTrivialMoveAssign, KEYALL)
+TYPE_TRAIT_1(__has_trivial_copy, HasTrivialCopy, KEYALL)
+TYPE_TRAIT_1(__has_trivial_constructor, HasTrivialDefaultConstructor, KEYALL)
+TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYALL)
+TYPE_TRAIT_1(__has_trivial_destructor, HasTrivialDestructor, KEYALL)
 TYPE_TRAIT_1(__has_virtual_destructor, HasVirtualDestructor, KEYCXX)
 TYPE_TRAIT_1(__is_abstract, IsAbstract, KEYCXX)
 TYPE_TRAIT_1(__is_aggregate, IsAggregate, KEYCXX)
Index: cfe/trunk/test/SemaObjC/non-trivial-struct-traits.m
===
--- cfe/trunk/test/SemaObjC/non-trivial-struct-traits.m
+++ cfe/trunk/test/SemaObjC/non-trivial-struct-traits.m
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only 

[PATCH] D44913: [ObjC] Enable using C++ triviality type traits for non-trivial C structs

2018-03-27 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328680: [ObjC] Make C++ triviality type traits available to 
non-trivial C (authored by ahatanak, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44913

Files:
  include/clang/Basic/TokenKinds.def
  lib/Sema/SemaExprCXX.cpp
  test/SemaObjC/non-trivial-struct-traits.m

Index: include/clang/Basic/TokenKinds.def
===
--- include/clang/Basic/TokenKinds.def
+++ include/clang/Basic/TokenKinds.def
@@ -433,12 +433,12 @@
 TYPE_TRAIT_1(__has_nothrow_move_assign, HasNothrowMoveAssign, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_constructor, HasNothrowConstructor, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_assign, HasTrivialAssign, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_move_assign, HasTrivialMoveAssign, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_copy, HasTrivialCopy, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_constructor, HasTrivialDefaultConstructor, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_destructor, HasTrivialDestructor, KEYCXX)
+TYPE_TRAIT_1(__has_trivial_assign, HasTrivialAssign, KEYALL)
+TYPE_TRAIT_1(__has_trivial_move_assign, HasTrivialMoveAssign, KEYALL)
+TYPE_TRAIT_1(__has_trivial_copy, HasTrivialCopy, KEYALL)
+TYPE_TRAIT_1(__has_trivial_constructor, HasTrivialDefaultConstructor, KEYALL)
+TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYALL)
+TYPE_TRAIT_1(__has_trivial_destructor, HasTrivialDestructor, KEYALL)
 TYPE_TRAIT_1(__has_virtual_destructor, HasVirtualDestructor, KEYCXX)
 TYPE_TRAIT_1(__is_abstract, IsAbstract, KEYCXX)
 TYPE_TRAIT_1(__is_aggregate, IsAggregate, KEYCXX)
Index: test/SemaObjC/non-trivial-struct-traits.m
===
--- test/SemaObjC/non-trivial-struct-traits.m
+++ test/SemaObjC/non-trivial-struct-traits.m
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify %s
+
+// expected-no-diagnostics
+
+struct Trivial {
+  int x;
+};
+
+struct NonTrivial {
+  id x;
+};
+
+int trivial_assign[__has_trivial_assign(struct Trivial) ? 1 : -1];
+int trivial_move_assign[__has_trivial_move_assign(struct Trivial) ? 1 : -1];
+int trivial_copy_constructor[__has_trivial_copy(struct Trivial) ? 1 : -1];
+int trivial_move_constructor[__has_trivial_move_constructor(struct Trivial) ? 1 : -1];
+int trivial_constructor[__has_trivial_constructor(struct Trivial) ? 1 : -1];
+int trivial_destructor[__has_trivial_destructor(struct Trivial) ? 1 : -1];
+
+int non_trivial_assign[__has_trivial_assign(struct NonTrivial) ? -1 : 1];
+int non_trivial_move_assign[__has_trivial_move_assign(struct NonTrivial) ? -1 : 1];
+int non_trivial_copy_constructor[__has_trivial_copy(struct NonTrivial) ? -1 : 1];
+int non_trivial_move_constructor[__has_trivial_move_constructor(struct NonTrivial) ? -1 : 1];
+int non_trivial_constructor[__has_trivial_constructor(struct NonTrivial) ? -1 : 1];
+int non_trivial_destructor[__has_trivial_destructor(struct NonTrivial) ? -1 : 1];
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -4513,6 +4513,8 @@
 // does not correctly compute triviality in the presence of multiple special
 // members of the same kind. Revisit this once the g++ bug is fixed.
   case UTT_HasTrivialDefaultConstructor:
+if (T.isNonTrivialToPrimitiveDefaultInitialize())
+  return false;
 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
 //   If __is_pod (type) is true then the trait is true, else if type is
 //   a cv class or union type (or array thereof) with a trivial default
@@ -4524,6 +4526,8 @@
  !RD->hasNonTrivialDefaultConstructor();
 return false;
   case UTT_HasTrivialMoveConstructor:
+if (T.isNonTrivialToPrimitiveDestructiveMove())
+  return false;
 //  This trait is implemented by MSVC 2012 and needed to parse the
 //  standard library headers. Specifically this is used as the logic
 //  behind std::is_trivially_move_constructible (20.9.4.3).
@@ -4533,6 +4537,8 @@
   return RD->hasTrivialMoveConstructor() && !RD->hasNonTrivialMoveConstructor();
 return false;
   case UTT_HasTrivialCopy:
+if (T.isNonTrivialToPrimitiveCopy())
+  return false;
 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
 //   If __is_pod (type) is true or type is a reference type then
 //   the trait is true, else if type is a cv class or union type
@@ -4545,6 +4551,8 @@
  !RD->hasNonTrivialCopyConstructor();
 return false;
   case UTT_HasTrivialMoveAssign:
+if (T.isNonTrivialToPrimitiveDestructiveMove())
+  return false;
 //  This trait is implemented by MSVC 2012 and needed to parse the
 //  standard library headers. Specifically it is used as 

[PATCH] D44801: Add the -fsanitize=shadow-call-stack flag

2018-03-27 Thread Kostya Serebryany via Phabricator via cfe-commits
kcc accepted this revision.
kcc added a comment.

LGTM modulo prolog vs prlogue and epilog vs epilogue

https://en.wiktionary.org/wiki/epilog says these are alternative spellings, so 
up to you.




Comment at: docs/ShadowCallStack.rst:14
+buffer overflows. It works by saving a function's return address to a
+separately allocated 'shadow call stack' in the function prolog and checking 
the
+return address on the stack against the shadow call stack in the function

kcc wrote:
> prologue/epilogue? 
> (it's your native tongue, not mine, though)
PTAL


Repository:
  rC Clang

https://reviews.llvm.org/D44801



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


r328680 - [ObjC] Make C++ triviality type traits available to non-trivial C

2018-03-27 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Mar 27 17:12:08 2018
New Revision: 328680

URL: http://llvm.org/viewvc/llvm-project?rev=328680=rev
Log:
[ObjC] Make C++ triviality type traits available to non-trivial C
structs.

r326307 and r327870 made changes that allowed using non-trivial C
structs with fields qualified with __strong or __weak. This commit makes
the following C++ triviality type traits available to non-trivial C
structs:

__has_trivial_assign
__has_trivial_move_assign
__has_trivial_copy
__has_trivial_move_constructor
__has_trivial_constructor
__has_trivial_destructor

rdar://problem/33599681

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

Added:
cfe/trunk/test/SemaObjC/non-trivial-struct-traits.m
Modified:
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=328680=328679=328680=diff
==
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Tue Mar 27 17:12:08 2018
@@ -433,12 +433,12 @@ TYPE_TRAIT_1(__has_nothrow_assign, HasNo
 TYPE_TRAIT_1(__has_nothrow_move_assign, HasNothrowMoveAssign, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_constructor, HasNothrowConstructor, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_assign, HasTrivialAssign, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_move_assign, HasTrivialMoveAssign, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_copy, HasTrivialCopy, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_constructor, HasTrivialDefaultConstructor, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
-TYPE_TRAIT_1(__has_trivial_destructor, HasTrivialDestructor, KEYCXX)
+TYPE_TRAIT_1(__has_trivial_assign, HasTrivialAssign, KEYALL)
+TYPE_TRAIT_1(__has_trivial_move_assign, HasTrivialMoveAssign, KEYALL)
+TYPE_TRAIT_1(__has_trivial_copy, HasTrivialCopy, KEYALL)
+TYPE_TRAIT_1(__has_trivial_constructor, HasTrivialDefaultConstructor, KEYALL)
+TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYALL)
+TYPE_TRAIT_1(__has_trivial_destructor, HasTrivialDestructor, KEYALL)
 TYPE_TRAIT_1(__has_virtual_destructor, HasVirtualDestructor, KEYCXX)
 TYPE_TRAIT_1(__is_abstract, IsAbstract, KEYCXX)
 TYPE_TRAIT_1(__is_aggregate, IsAggregate, KEYCXX)

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=328680=328679=328680=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Mar 27 17:12:08 2018
@@ -4513,6 +4513,8 @@ static bool EvaluateUnaryTypeTrait(Sema
 // does not correctly compute triviality in the presence of multiple 
special
 // members of the same kind. Revisit this once the g++ bug is fixed.
   case UTT_HasTrivialDefaultConstructor:
+if (T.isNonTrivialToPrimitiveDefaultInitialize())
+  return false;
 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
 //   If __is_pod (type) is true then the trait is true, else if type is
 //   a cv class or union type (or array thereof) with a trivial default
@@ -4524,6 +4526,8 @@ static bool EvaluateUnaryTypeTrait(Sema
  !RD->hasNonTrivialDefaultConstructor();
 return false;
   case UTT_HasTrivialMoveConstructor:
+if (T.isNonTrivialToPrimitiveDestructiveMove())
+  return false;
 //  This trait is implemented by MSVC 2012 and needed to parse the
 //  standard library headers. Specifically this is used as the logic
 //  behind std::is_trivially_move_constructible (20.9.4.3).
@@ -4533,6 +4537,8 @@ static bool EvaluateUnaryTypeTrait(Sema
   return RD->hasTrivialMoveConstructor() && 
!RD->hasNonTrivialMoveConstructor();
 return false;
   case UTT_HasTrivialCopy:
+if (T.isNonTrivialToPrimitiveCopy())
+  return false;
 // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html:
 //   If __is_pod (type) is true or type is a reference type then
 //   the trait is true, else if type is a cv class or union type
@@ -4545,6 +4551,8 @@ static bool EvaluateUnaryTypeTrait(Sema
  !RD->hasNonTrivialCopyConstructor();
 return false;
   case UTT_HasTrivialMoveAssign:
+if (T.isNonTrivialToPrimitiveDestructiveMove())
+  return false;
 //  This trait is implemented by MSVC 2012 and needed to parse the
 //  standard library headers. Specifically it is used as the logic
 //  behind std::is_trivially_move_assignable (20.9.4.3)
@@ -4554,6 +4562,8 @@ static bool EvaluateUnaryTypeTrait(Sema
   return RD->hasTrivialMoveAssignment() && 
!RD->hasNonTrivialMoveAssignment();
 return false;
   case UTT_HasTrivialAssign:
+if (T.isNonTrivialToPrimitiveCopy())
+  return false;
   

[PATCH] D43667: [clang-doc] Implement a YAML generator

2018-03-27 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 140021.
juliehockett added a comment.

Updating to for adjustments to the internal representation & cleaning up 
duplication.


https://reviews.llvm.org/D43667

Files:
  clang-doc/CMakeLists.txt
  clang-doc/Representation.h
  clang-doc/generators/CMakeLists.txt
  clang-doc/generators/Generators.h
  clang-doc/generators/YAMLGenerator.cpp
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/yaml-comments.cpp
  test/clang-doc/yaml-namespace.cpp
  test/clang-doc/yaml-record.cpp

Index: test/clang-doc/yaml-record.cpp
===
--- /dev/null
+++ test/clang-doc/yaml-record.cpp
@@ -0,0 +1,212 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: cat %t/docs/yaml/docs.yaml | FileCheck %s
+
+union A { int X; int Y; };
+
+enum B { X, Y };
+
+enum class Bc { A, B };
+
+struct C { int i; };
+
+class D {};
+
+class E {
+public:
+  E() {}
+  ~E() {}
+
+protected:
+  void ProtectedMethod();
+};
+
+void E::ProtectedMethod() {}
+
+class F : virtual private D, public E {};
+
+class X {
+  class Y {};
+};
+
+void H() {
+  class I {};
+}
+
+// CHECK: ---
+// CHECK-NEXT: Records: 
+// CHECK-NEXT:   - USR: 'ACE81AFA6627B4CEF2B456FB6E1252925674AF7E'
+// CHECK-NEXT: Name:'A'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  8
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: TagType: Union
+// CHECK-NEXT: Members: 
+// CHECK-NEXT:   - Type:
+// CHECK-NEXT:   UnresolvedName:  'int'
+// CHECK-NEXT: Name:'A::X'
+// CHECK-NEXT:   - Type:
+// CHECK-NEXT:   UnresolvedName:  'int'
+// CHECK-NEXT: Name:'A::Y'
+// CHECK-NEXT:   - USR: '06B5F6A19BA9F6A832E127C9968282B94619B210'
+// CHECK-NEXT: Name:'C'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  14
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: Members: 
+// CHECK-NEXT:   - Type:
+// CHECK-NEXT:   UnresolvedName:  'int'
+// CHECK-NEXT: Name:'C::i'
+// CHECK-NEXT:   - USR: '0921737541208B8FA9BB42B60F78AC1D779AA054'
+// CHECK-NEXT: Name:'D'
+// CHECK-NEXT: Records: 
+// CHECK-NEXT:   - Type:Record
+// CHECK-NEXT: USR: 'E3B54702FABFF4037025BA194FC27C47006330B5'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  16
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT:   - USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT: Name:'E'
+// CHECK-NEXT: Records: 
+// CHECK-NEXT:   - Type:Record
+// CHECK-NEXT: USR: 'E3B54702FABFF4037025BA194FC27C47006330B5'
+// CHECK-NEXT: Functions:   
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: 'DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: 'DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: 'BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: 'BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: '5093D428CDC62096A67547BA52566E4FB9404EEE'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: '5093D428CDC62096A67547BA52566E4FB9404EEE'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  18
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT:   - USR: 'E3B54702FABFF4037025BA194FC27C47006330B5'
+// CHECK-NEXT: Name:'F'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  29
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT: Parents: 
+// CHECK-NEXT:   - Type:Record
+// CHECK-NEXT: USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT: VirtualParents:  
+// CHECK-NEXT:   - Type:Record
+// CHECK-NEXT: USR: '0921737541208B8FA9BB42B60F78AC1D779AA054'
+// CHECK-NEXT:   - USR: 'CA7C7935730B5EACD25F080E9C83FA087CCDC75E'
+// CHECK-NEXT: Name:'X'
+// CHECK-NEXT: Records: 
+// CHECK-NEXT:   - Type:Record
+// CHECK-NEXT:   

[PATCH] D44948: Add diagnostic -Waggregate-ctors, "aggregate type has user-declared constructors"

2018-03-27 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone planned changes to this revision.
Quuxplusone added a comment.

This is related to an upcoming C++ paper, definitely not ready for prime time 
(e.g. no tests), and quite possibly never will be ready (although if people 
thought it would be useful, I'd be happy to clean it up and add tests).
I'll mark it "Plan Changes" for now and perhaps just abandon it in a few 
days/weeks. Sorry I didn't mark it as such to begin with.


Repository:
  rC Clang

https://reviews.llvm.org/D44948



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


[PATCH] D44948: Add diagnostic -Waggregate-ctors, "aggregate type has user-declared constructors"

2018-03-27 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please mention new diagnostics in documentation and Release Notes.


Repository:
  rC Clang

https://reviews.llvm.org/D44948



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


[PATCH] D41938: [Analyzer] SValBuilder Comparison Rearrangement (with Restrictions and Analyzer Option)

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

This looks good with a super tiny nit regarding comments about signed integers. 
George, are you happy with the changes? (:




Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:675-677
+  /// is on the right. This is only done if both concrete integers are greater
+  /// than or equal to the quarter of the minimum value of the type and less
+  /// than or equal to the quarter of the maximum value of that type.

I believe that we should mention that the integers are signed.



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:330
+  nonloc::ConcreteInt(Max), SVB.getConditionType());
+  if (auto DV = IsCappedFromAbove.getAs()) {
+if (State->assume(*DV, false))

baloghadamsoftware wrote:
> george.karpenkov wrote:
> > 6 lines of branching is probably better expressed as
> > 
> > ```
> > if (!isa(IsCappedFromAbove) || 
> > State->assume(*dyn_cast(IsCappedFromAbove), false))
> >return false
> > ```
> SVal is not a pointer, so isa<>() and dyn_cast<>() does not work here.
`.getAs<>()` would have been similar, but i'm not fond of double checks either.



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:429
+  if (BinaryOperator::isComparisonOp(Op)) {
+// Prefer comparing to a non-negative number.
+// FIXME: Maybe it'd be better to have consistency in

george.karpenkov wrote:
> It seems that having a concrete positive RHS is a part of your rewrite rule. 
> In that case, that should be documented in a high-level overview of the 
> rewrite rules.
That's an invariant that we're maintaining in other places as well.



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:774
 
+  if (Optional V = tryRearrange(state, op, lhs, rhs, resultTy))
+return *V;

george.karpenkov wrote:
> I would expect that checking the analyzer option would be performed here?
> 
Nope, not yet. The flag is only for range-checked rearrangements.


https://reviews.llvm.org/D41938



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


[PATCH] D44901: [Diag] Avoid emitting a redefinition note if no location is available.

2018-03-27 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D44901



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


[PATCH] D44964: Change order of libclang_rt.profile link for freebsd

2018-03-27 Thread Tom Rix via Phabricator via cfe-commits
trixirt created this revision.
trixirt added reviewers: emaste, rsmith.
Herald added a subscriber: cfe-commits.

clang -static -coverage foo.c  fails because the -lclang_rt.profile-*.a has a 
dependency on libc but is placed after libc in the link line.
This change place -lclang_rt.profile before -lc.


Repository:
  rC Clang

https://reviews.llvm.org/D44964

Files:
  lib/Driver/ToolChains/FreeBSD.cpp


Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -262,6 +262,8 @@
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
+  ToolChain.addProfileRTLibs(Args, CmdArgs);
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 addOpenMPRuntime(CmdArgs, ToolChain, Args);
 if (D.CCCIsCXX()) {
@@ -329,8 +331,6 @@
 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
   }
 
-  ToolChain.addProfileRTLibs(Args, CmdArgs);
-
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }


Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -262,6 +262,8 @@
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
+  ToolChain.addProfileRTLibs(Args, CmdArgs);
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 addOpenMPRuntime(CmdArgs, ToolChain, Args);
 if (D.CCCIsCXX()) {
@@ -329,8 +331,6 @@
 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
   }
 
-  ToolChain.addProfileRTLibs(Args, CmdArgs);
-
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44765: PR36643 Make clang-format support more generic TMarcos

2018-03-27 Thread Teodor Petrov via Phabricator via cfe-commits
obfuscated marked an inline comment as done.
obfuscated added inline comments.



Comment at: lib/Format/FormatToken.h:138
+  /// \brief Whether this is a string literal similar to _T("sdfsdf").
+  bool TMacroStringLiteral = false;
+

krasimir wrote:
> We don't strictly need this new field. We could do as in the old 
> implementation and check if the string prefix is from a T macro in 
> ContinuationIndenter.
Using a flag is more reliable and faster - the checks are done once, so they 
don't have to be repeated.

From the field layout in the struct and from the usage of bools I could only 
conclude that this is not a memory nor performance critical part of the code.




Comment at: unittests/Format/FormatTest.cpp:10693
+
+  // FIXME: This is required because parsing a configuration simply overwrites
+  // the first N elements of the list instead of resetting it.

krasimir wrote:
> Why is the `FIXME` here? I suggest just use the pattern similar to the other 
> cases here and just keep the test with 2 elements:
> ```
> Style.TMacros.clear();
> std::vector ExpectedTMacros = {"_T", "myT"};
> CHECK_PARSE("TMacros: [_T, myT]", TMacros, ExpectedTMacros);
> ```
I've copy pasted this from the foreach macro option.
I've not investigate why this fixme is there.


Repository:
  rC Clang

https://reviews.llvm.org/D44765



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


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-27 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

Some quick first pass comments.




Comment at: lib/CodeGen/CGCleanup.cpp:985
+// does not have a runtime support for that.
+if (!Personality.usesFuncletPads() || Personality.isWasmPersonality()) {
+  EHStack.pushTerminate();

I think this condition can be simplified to `!isMSVCPersonality()` with a 
slight tweak of the comment.



Comment at: test/CodeGenCXX/wasm-eh.cpp:33
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* 
bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)]
+// CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.get.exception()
+// CHECK-NEXT:   store i8* %[[EXN]], i8** %exn.slot

I'd expect a funclet bundle operand here..


Repository:
  rC Clang

https://reviews.llvm.org/D44931



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


[PATCH] D44947: [Driver] Add fuzzer-no-link into the list of supported Fuchsia sanitizers

2018-03-27 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328672: [Driver] Add fuzzer-no-link into the list of 
supported Fuchsia sanitizers (authored by phosek, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44947?vs=139978=140007#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44947

Files:
  lib/Driver/ToolChains/Fuchsia.cpp


Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -280,6 +280,7 @@
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::FuzzerNoLink;
   Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;


Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -280,6 +280,7 @@
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::FuzzerNoLink;
   Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328672 - [Driver] Add fuzzer-no-link into the list of supported Fuchsia sanitizers

2018-03-27 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Mar 27 14:33:12 2018
New Revision: 328672

URL: http://llvm.org/viewvc/llvm-project?rev=328672=rev
Log:
[Driver] Add fuzzer-no-link into the list of supported Fuchsia sanitizers

This is needed in addition to fuzzer in order to use libFuzzer.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp?rev=328672=328671=328672=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Tue Mar 27 14:33:12 2018
@@ -280,6 +280,7 @@ SanitizerMask Fuchsia::getSupportedSanit
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::FuzzerNoLink;
   Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;


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


[PATCH] D42938: [Sema] Emit -Winteger-overflow for arguments in function calls, ObjC messages.

2018-03-27 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328671: [Sema] Emit -Winteger-overflow for arguments in 
function calls, ObjC messages. (authored by vsapsai, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42938?vs=132917=140006#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42938

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/Sema/integer-overflow.c
  cfe/trunk/test/SemaCXX/integer-overflow.cpp
  cfe/trunk/test/SemaObjC/integer-overflow.m

Index: cfe/trunk/test/SemaCXX/integer-overflow.cpp
===
--- cfe/trunk/test/SemaCXX/integer-overflow.cpp
+++ cfe/trunk/test/SemaCXX/integer-overflow.cpp
@@ -169,3 +169,18 @@
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
 }
+
+void check_integer_overflows_in_function_calls() {
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  (void)f0(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  uint64_t x = f0(4608 * 1024 * 1024);
+
+// expected-warning@+2 {{overflow in expression; result is 536870912 with type 'int'}}
+  uint64_t (*f0_ptr)(uint64_t) = 
+  (void)(*f0_ptr)(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  (void)f2(0, f0(4608 * 1024 * 1024));
+}
Index: cfe/trunk/test/Sema/integer-overflow.c
===
--- cfe/trunk/test/Sema/integer-overflow.c
+++ cfe/trunk/test/Sema/integer-overflow.c
@@ -158,6 +158,21 @@
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
 }
 
+void check_integer_overflows_in_function_calls() {
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  (void)f0(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  uint64_t x = f0(4608 * 1024 * 1024);
+
+// expected-warning@+2 {{overflow in expression; result is 536870912 with type 'int'}}
+  uint64_t (*f0_ptr)(uint64_t) = 
+  (void)(*f0_ptr)(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  (void)f2(0, f0(4608 * 1024 * 1024));
+}
+
 struct s {
   unsigned x;
   unsigned y;
Index: cfe/trunk/test/SemaObjC/integer-overflow.m
===
--- cfe/trunk/test/SemaObjC/integer-overflow.m
+++ cfe/trunk/test/SemaObjC/integer-overflow.m
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -Wno-objc-root-class -fsyntax-only -verify %s
+
+@interface Foo
+@end
+
+@implementation Foo
+- (int)add:(int)a with:(int)b {
+  return a + b;
+}
+
+- (void)testIntegerOverflows {
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  (void)[self add:0 with:4608 * 1024 * 1024];
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  (void)[self add:0 with:[self add:4608 * 1024 * 1024 with:0]];
+}
+@end
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -10225,18 +10225,22 @@
   SmallVector Exprs(1, E);
 
   do {
-Expr *E = Exprs.pop_back_val();
+Expr *OriginalE = Exprs.pop_back_val();
+Expr *E = OriginalE->IgnoreParenCasts();
 
-if (isa(E->IgnoreParenCasts())) {
-  E->IgnoreParenCasts()->EvaluateForOverflow(Context);
+if (isa(E)) {
+  E->EvaluateForOverflow(Context);
   continue;
 }
 
-if (auto InitList = dyn_cast(E))
+if (auto InitList = dyn_cast(OriginalE))
   Exprs.append(InitList->inits().begin(), InitList->inits().end());
-
-if (isa(E))
-  E->IgnoreParenCasts()->EvaluateForOverflow(Context);
+else if (isa(OriginalE))
+  E->EvaluateForOverflow(Context);
+else if (auto Call = dyn_cast(E))
+  Exprs.append(Call->arg_begin(), Call->arg_end());
+else if (auto Message = dyn_cast(E))
+  Exprs.append(Message->arg_begin(), Message->arg_end());
   } while (!Exprs.empty());
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328671 - [Sema] Emit -Winteger-overflow for arguments in function calls, ObjC messages.

2018-03-27 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Tue Mar 27 14:29:05 2018
New Revision: 328671

URL: http://llvm.org/viewvc/llvm-project?rev=328671=rev
Log:
[Sema] Emit -Winteger-overflow for arguments in function calls, ObjC messages.

rdar://problem/35539384

Reviewers: ahatanak, nicholas, rsmith, jkorous-apple

Reviewed By: jkorous-apple

Subscribers: cfe-commits, jkorous-apple

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


Added:
cfe/trunk/test/SemaObjC/integer-overflow.m
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/integer-overflow.c
cfe/trunk/test/SemaCXX/integer-overflow.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=328671=328670=328671=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Mar 27 14:29:05 2018
@@ -10225,18 +10225,22 @@ void Sema::CheckForIntOverflow (Expr *E)
   SmallVector Exprs(1, E);
 
   do {
-Expr *E = Exprs.pop_back_val();
+Expr *OriginalE = Exprs.pop_back_val();
+Expr *E = OriginalE->IgnoreParenCasts();
 
-if (isa(E->IgnoreParenCasts())) {
-  E->IgnoreParenCasts()->EvaluateForOverflow(Context);
+if (isa(E)) {
+  E->EvaluateForOverflow(Context);
   continue;
 }
 
-if (auto InitList = dyn_cast(E))
+if (auto InitList = dyn_cast(OriginalE))
   Exprs.append(InitList->inits().begin(), InitList->inits().end());
-
-if (isa(E))
-  E->IgnoreParenCasts()->EvaluateForOverflow(Context);
+else if (isa(OriginalE))
+  E->EvaluateForOverflow(Context);
+else if (auto Call = dyn_cast(E))
+  Exprs.append(Call->arg_begin(), Call->arg_end());
+else if (auto Message = dyn_cast(E))
+  Exprs.append(Message->arg_begin(), Message->arg_end());
   } while (!Exprs.empty());
 }
 

Modified: cfe/trunk/test/Sema/integer-overflow.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/integer-overflow.c?rev=328671=328670=328671=diff
==
--- cfe/trunk/test/Sema/integer-overflow.c (original)
+++ cfe/trunk/test/Sema/integer-overflow.c Tue Mar 27 14:29:05 2018
@@ -158,6 +158,21 @@ uint64_t check_integer_overflows(int i)
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
 }
 
+void check_integer_overflows_in_function_calls() {
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+  (void)f0(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+  uint64_t x = f0(4608 * 1024 * 1024);
+
+// expected-warning@+2 {{overflow in expression; result is 536870912 with type 
'int'}}
+  uint64_t (*f0_ptr)(uint64_t) = 
+  (void)(*f0_ptr)(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+  (void)f2(0, f0(4608 * 1024 * 1024));
+}
+
 struct s {
   unsigned x;
   unsigned y;

Modified: cfe/trunk/test/SemaCXX/integer-overflow.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/integer-overflow.cpp?rev=328671=328670=328671=diff
==
--- cfe/trunk/test/SemaCXX/integer-overflow.cpp (original)
+++ cfe/trunk/test/SemaCXX/integer-overflow.cpp Tue Mar 27 14:29:05 2018
@@ -169,3 +169,18 @@ uint64_t check_integer_overflows(int i)
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}}
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
 }
+
+void check_integer_overflows_in_function_calls() {
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+  (void)f0(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+  uint64_t x = f0(4608 * 1024 * 1024);
+
+// expected-warning@+2 {{overflow in expression; result is 536870912 with type 
'int'}}
+  uint64_t (*f0_ptr)(uint64_t) = 
+  (void)(*f0_ptr)(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+  (void)f2(0, f0(4608 * 1024 * 1024));
+}

Added: cfe/trunk/test/SemaObjC/integer-overflow.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/integer-overflow.m?rev=328671=auto
==
--- cfe/trunk/test/SemaObjC/integer-overflow.m (added)
+++ cfe/trunk/test/SemaObjC/integer-overflow.m Tue Mar 27 14:29:05 2018
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -Wno-objc-root-class -fsyntax-only -verify %s
+
+@interface Foo
+@end
+
+@implementation Foo
+- (int)add:(int)a with:(int)b {
+  return a + b;
+}
+
+- (void)testIntegerOverflows {
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
+  (void)[self add:0 with:4608 * 1024 * 1024];
+
+// 

[PATCH] D44882: [clangd] Implementation of workspace/symbol request

2018-03-27 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

The index changes are moved here: https://reviews.llvm.org/D44954 I haven't 
changed the patch yet though, I just removed it from this one.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44882



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


[PATCH] D44954: [clangd] [RFC] Add more symbols to the index

2018-03-27 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle planned changes to this revision.
malaperle added inline comments.



Comment at: clangd/index/Index.h:142
+  // Whether or not the symbol should be considered for completion.
+  bool ForCompletion = false;
   /// A brief description of the symbol that can be displayed in the completion

I'm thinking of replacing this with something like:
Decl::Kind DeclContextKind;
bool IsScoped (enum);
bool IsInMainFile;



Comment at: clangd/index/Index.h:255
+  /// A flag to restrict the results to completion matches.
+  bool CompletionMatchesOnly = false;
 };

Would be removed when "ForCompletion" is replaced.



Comment at: clangd/index/MemIndex.cpp:48
 continue;
+  if (Req.CompletionMatchesOnly && !Sym->ForCompletion)
+continue;

Would be removed when "ForCompletion" is replaced.



Comment at: clangd/index/SymbolCollector.cpp:124
+
+bool isForCompletion(const NamedDecl *ND, ASTContext *ASTCtx) {
+  using namespace clang::ast_matchers;

This code would be replaced with setting individual Symbol fields instead.



Comment at: clangd/index/SymbolCollector.cpp:342
+  if (isForCompletion(, ASTCtx)) {
+S.ForCompletion = true;
+getLabelAndInsertText(*CCS, , ,

Here we would set fields that will replace "ForCompletion"


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44954



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


[PATCH] D44955: [CFG] [analyzer] Work around a disappearing CXXBindTemporaryExpr.

2018-03-27 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.

This is a CFG-side patch for the weird AST i encountered in 
http://lists.llvm.org/pipermail/cfe-dev/2018-March/057398.html . The omission 
of the `CXXBindTemporaryExpr` causes a crash because it produces an unexpected 
construction context for a temporary object that requires non-trivial 
destruction.

I removed the crashing assertion for now, together with the ill-formed 
construction context. Temporary destructor is still missing from the CFG in 
this case, so it was important to remove the construction context, so that not 
to try modeling the constructor when the destructor is completely missing.

CodeGen works fine because they defensively destroy everything they ever wanted 
to destroy at `ExprWithCleanups`.


Repository:
  rC Clang

https://reviews.llvm.org/D44955

Files:
  include/clang/Analysis/ConstructionContext.h
  lib/Analysis/CFG.cpp
  lib/Analysis/ConstructionContext.cpp
  test/Analysis/missing-bind-temporary.cpp

Index: test/Analysis/missing-bind-temporary.cpp
===
--- /dev/null
+++ test/Analysis/missing-bind-temporary.cpp
@@ -0,0 +1,130 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++14 -verify %s
+
+void clang_analyzer_eval(bool);
+
+int global;
+
+namespace variant_0 {
+// This variant of the code works correctly. Function foo() is not a template
+// function. Note that there are two destructors within foo().
+
+class A {
+public:
+  ~A() { ++global; }
+};
+
+class B {
+  A a;
+};
+
+// CHECK: void foo(int)
+// CHECK:   [B1]
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], class variant_0::B)
+// CHECK-NEXT:2: variant_0::B i;
+// CHECK-NEXT:3: operator=
+// CHECK-NEXT:4: [B1.3] (ImplicitCastExpr, FunctionToPointerDecay, class variant_0::B &(*)(class variant_0::B &&) noexcept)
+// CHECK-NEXT:5: i
+// CHECK-NEXT:6: {} (CXXConstructExpr, [B1.7], [B1.8], class variant_0::B)
+// CHECK-NEXT:7: [B1.6] (BindTemporary)
+// CHECK-NEXT:8: [B1.7]
+// CHECK-NEXT:9: [B1.5] = [B1.8] (OperatorCall)
+// CHECK-NEXT:   10: ~variant_0::B() (Temporary object destructor)
+// CHECK-NEXT:   11: [B1.2].~B() (Implicit destructor)
+void foo(int) {
+  B i;
+  i = {};
+}
+
+void bar() {
+  global = 0;
+  foo(1);
+  clang_analyzer_eval(global == 2); // expected-warning{{TRUE}}
+}
+
+} // end namespace variant_0
+
+namespace variant_1 {
+// Suddenly, if we turn foo() into a template, we are missing a
+// CXXBindTemporaryExpr in the AST, and therefore we're missing a
+// temporary destructor in the CFG.
+
+class A {
+public:
+  ~A() { ++global; }
+};
+
+class B {
+  A a;
+};
+
+// FIXME: Find the construction context for {} and enforce the temporary
+// destructor.
+// CHECK: template<> void foo(int)
+// CHECK:   [B1]
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], class variant_1::B)
+// CHECK-NEXT:2: variant_1::B i;
+// CHECK-NEXT:3: operator=
+// CHECK-NEXT:4: [B1.3] (ImplicitCastExpr, FunctionToPointerDecay, class variant_1::B &(*)(class variant_1::B &&) noexcept)
+// CHECK-NEXT:5: i
+// CHECK-NEXT:6: {} (CXXConstructExpr, class variant_1::B)
+// CHECK-NEXT:7: [B1.6]
+// CHECK-NEXT:8: [B1.5] = [B1.7] (OperatorCall)
+// CHECK-NEXT:9: [B1.2].~B() (Implicit destructor)
+template  void foo(T) {
+  B i;
+  i = {};
+}
+
+void bar() {
+  global = 0;
+  foo(1);
+  // FIXME: Should be TRUE, i.e. we should call (and inline) two destructors.
+  clang_analyzer_eval(global == 2); // expected-warning{{UNKNOWN}}
+}
+
+} // end namespace variant_1
+
+namespace variant_2 {
+// Making field 'a' in class 'B' public turns the class into an aggregate.
+// In this case there is no constructor at {} - only an aggregate
+// initialization. Aggregate initialization is unsupported for now.
+
+class A {
+public:
+  ~A() { ++global; }
+};
+
+class B {
+public:
+  A a;
+};
+
+// CHECK: template<> void foo(int)
+// CHECK:   [B1]
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], class variant_2::B)
+// CHECK-NEXT:2: variant_2::B i;
+// CHECK-NEXT:3: operator=
+// CHECK-NEXT:4: [B1.3] (ImplicitCastExpr, FunctionToPointerDecay, class variant_2::B &(*)(class variant_2::B &&) noexcept)
+// CHECK-NEXT:5: i
+// CHECK-NEXT:6: {}
+// CHECK-NEXT:7: {}
+// CHECK-NEXT:8: [B1.7] (BindTemporary)
+// CHECK-NEXT:9: [B1.8]
+// CHECK-NEXT:   10: [B1.5] = [B1.9] (OperatorCall)
+// CHECK-NEXT:   11: ~variant_2::B() (Temporary object destructor)
+// CHECK-NEXT:   12: [B1.2].~B() (Implicit destructor)
+template  void foo(T) {
+  B i;
+  i = {};
+}
+
+void bar() {
+  global = 0;
+  foo(1);
+  // FIXME: Should be TRUE, i.e. we should call (and inline) two destructors.
+  clang_analyzer_eval(global 

[PATCH] D44954: [clangd] [RFC] Add more symbols to the index

2018-03-27 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle created this revision.
Herald added subscribers: cfe-commits, MaskRay, ioeric, jkorous-apple, 
ilya-biryukov, klimek.

This adds more symbols to the index:

- member variables and functions
- symbols in main files
- enum constants in scoped enums

This is a WIP meant as a starting point for discussion towards a better
version.

Signed-off-by: Marc-Andre Laperle 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44954

Files:
  clangd/CodeComplete.cpp
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolYAML.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -60,6 +60,9 @@
  arg.Definition.EndOffset == Offsets.second;
 }
 MATCHER_P(Refs, R, "") { return int(arg.References) == R; }
+MATCHER_P(ForCompletion, ForCompletion, "") {
+  return arg.ForCompletion == ForCompletion;
+}
 
 namespace clang {
 namespace clangd {
@@ -191,25 +194,29 @@
 } // namespace foo
   )";
   runSymbolCollector(Header, /*Main=*/"");
-  EXPECT_THAT(Symbols,
-  UnorderedElementsAreArray(
-  {QName("Foo"), QName("f1"), QName("f2"), QName("KInt"),
-   QName("kStr"), QName("foo"), QName("foo::bar"),
-   QName("foo::int32"), QName("foo::int32_t"), QName("foo::v1"),
-   QName("foo::bar::v2"), QName("foo::baz")}));
+  EXPECT_THAT(
+  Symbols,
+  UnorderedElementsAreArray(
+  {QName("Foo"), QName("Foo::f"), QName("f1"), QName("f2"),
+   QName("KInt"), QName("kStr"), QName("foo"), QName("foo::bar"),
+   QName("foo::int32"), QName("foo::int32_t"), QName("foo::v1"),
+   QName("foo::bar::v2"), QName("foo::baz")}));
 }
 
 TEST_F(SymbolCollectorTest, Template) {
   Annotations Header(R"(
 // Template is indexed, specialization and instantiation is not.
-template  struct [[Tmpl]] {T x = 0;};
+template  struct [[Tmpl]] {T $xdecl[[x]] = 0;};
 template <> struct Tmpl {};
 extern template struct Tmpl;
 template struct Tmpl;
   )");
   runSymbolCollector(Header.code(), /*Main=*/"");
-  EXPECT_THAT(Symbols, UnorderedElementsAreArray({AllOf(
-   QName("Tmpl"), DeclRange(Header.offsetRange()))}));
+  EXPECT_THAT(
+  Symbols,
+  UnorderedElementsAreArray(
+  {AllOf(QName("Tmpl"), DeclRange(Header.offsetRange())),
+   AllOf(QName("Tmpl::x"), DeclRange(Header.offsetRange("xdecl")))}));
 }
 
 TEST_F(SymbolCollectorTest, Locations) {
@@ -228,7 +235,7 @@
 void $printdef[[print]]() {}
 
 // Declared/defined in main only.
-int Y;
+int $ydecl[[Y]];
   )cpp");
   runSymbolCollector(Header.code(), Main.code());
   EXPECT_THAT(
@@ -240,7 +247,8 @@
 DefRange(Main.offsetRange("clsdef"))),
   AllOf(QName("print"), DeclRange(Header.offsetRange("printdecl")),
 DefRange(Main.offsetRange("printdef"))),
-  AllOf(QName("Z"), DeclRange(Header.offsetRange("zdecl");
+  AllOf(QName("Z"), DeclRange(Header.offsetRange("zdecl"))),
+  AllOf(QName("Y"), DeclRange(Main.offsetRange("ydecl");
 }
 
 TEST_F(SymbolCollectorTest, References) {
@@ -262,10 +270,11 @@
   CollectorOpts.CountReferences = true;
   runSymbolCollector(Header, Main);
   EXPECT_THAT(Symbols,
-  UnorderedElementsAre(AllOf(QName("W"), Refs(1)),
-   AllOf(QName("X"), Refs(1)),
-   AllOf(QName("Y"), Refs(0)),
-   AllOf(QName("Z"), Refs(0)), QName("y")));
+  UnorderedElementsAre(
+  AllOf(QName("W"), Refs(1)), AllOf(QName("X"), Refs(1)),
+  AllOf(QName("Y"), Refs(0)), AllOf(QName("Z"), Refs(0)),
+  QName("y"), QName("w"), QName("w2"), QName("x"), QName("V"),
+  QName("v")));
 }
 
 TEST_F(SymbolCollectorTest, SymbolRelativeNoFallback) {
@@ -320,29 +329,31 @@
   Green
 };
 enum class Color2 {
-  Yellow // ignore
+  Yellow
 };
 namespace ns {
 enum {
   Black
 };
 }
   )";
   runSymbolCollector(Header, /*Main=*/"");
-  EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Red"), QName("Color"),
-QName("Green"), QName("Color2"),
-QName("ns"), QName("ns::Black")));
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAre(QName("Red"), QName("Color"), QName("Green"),
+   QName("Color2"), QName("Color2::Yellow"),
+   QName("ns"), QName("ns::Black")));
 }
 

r328663 - [coroutines] Do not attempt to typo-correct when coroutine is looking for required members

2018-03-27 Thread Gor Nishanov via cfe-commits
Author: gornishanov
Date: Tue Mar 27 13:38:19 2018
New Revision: 328663

URL: http://llvm.org/viewvc/llvm-project?rev=328663=rev
Log:
[coroutines] Do not attempt to typo-correct when coroutine is looking for 
required members

When SemaCoroutine looks for await_resume, it means it. No need for helpful: 
"Did you mean await_ready?" messages.

Fixes PR33477 and a couple of FIXMEs in test/SemaCXX/coroutines.cpp

Modified:
cfe/trunk/lib/Sema/SemaCoroutine.cpp
cfe/trunk/test/SemaCXX/coroutines.cpp

Modified: cfe/trunk/lib/Sema/SemaCoroutine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCoroutine.cpp?rev=328663=328662=328663=diff
==
--- cfe/trunk/lib/Sema/SemaCoroutine.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCoroutine.cpp Tue Mar 27 13:38:19 2018
@@ -362,6 +362,15 @@ static ExprResult buildMemberCall(Sema &
   if (Result.isInvalid())
 return ExprError();
 
+  // We meant exactly what we asked for. No need for typo correction.
+  if (auto *TE = dyn_cast(Result.get())) {
+S.clearDelayedTypo(TE);
+S.Diag(Loc, diag::err_no_member)
+<< NameInfo.getName() << Base->getType()->getAsCXXRecordDecl()
+<< Base->getSourceRange();
+return ExprError();
+  }
+
   return S.ActOnCallExpr(nullptr, Result.get(), Loc, Args, Loc, nullptr);
 }
 

Modified: cfe/trunk/test/SemaCXX/coroutines.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/coroutines.cpp?rev=328663=328662=328663=diff
==
--- cfe/trunk/test/SemaCXX/coroutines.cpp (original)
+++ cfe/trunk/test/SemaCXX/coroutines.cpp Tue Mar 27 13:38:19 2018
@@ -510,8 +510,7 @@ coro missing_get_return_o
 
 struct bad_promise_2 {
   coro get_return_object();
-  // FIXME: We shouldn't offer a typo-correction here!
-  suspend_always final_suspend(); // expected-note {{here}}
+  suspend_always final_suspend();
   void unhandled_exception();
   void return_void();
 };
@@ -522,8 +521,7 @@ coro missing_initial_susp
 
 struct bad_promise_3 {
   coro get_return_object();
-  // FIXME: We shouldn't offer a typo-correction here!
-  suspend_always initial_suspend(); // expected-note {{here}}
+  suspend_always initial_suspend();
   void unhandled_exception();
   void return_void();
 };
@@ -1378,3 +1376,22 @@ test_unused_warning() {
   co_await awaitable_unused_warn(); // expected-warning {{ignoring return 
value of function declared with 'nodiscard' attribute}}
   co_yield 42; // expected-warning {{ignoring return value of function 
declared with 'nodiscard' attribute}}
 }
+
+struct missing_await_ready {
+  void await_suspend(std::experimental::coroutine_handle<>);
+  void await_resume();
+};
+struct missing_await_suspend {
+  bool await_ready();
+  void await_resume();
+};
+struct missing_await_resume {
+  bool await_ready();
+  void await_suspend(std::experimental::coroutine_handle<>);
+};
+
+void test_missing_awaitable_members() {
+  co_await missing_await_ready{}; // expected-error {{no member named 
'await_ready' in 'missing_await_ready'}}
+  co_await missing_await_suspend{}; // expected-error {{no member named 
'await_suspend' in 'missing_await_suspend'}}
+  co_await missing_await_resume{}; // expected-error {{no member named 
'await_resume' in 'missing_await_resume'}}
+}


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


[PATCH] D42034: [clang-format] In tests, expected code should be format-stable

2018-03-27 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir requested changes to this revision.
krasimir added a comment.
This revision now requires changes to proceed.

Thank you!
If this works, we should apply it to all files in `unittest/Format`.


Repository:
  rC Clang

https://reviews.llvm.org/D42034



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


[PATCH] D44947: [Driver] Add fuzzer-no-link into the list of supported Fuchsia sanitizers

2018-03-27 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr accepted this revision.
mcgrathr added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rC Clang

https://reviews.llvm.org/D44947



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


[PATCH] D44765: PR36643 Make clang-format support more generic TMarcos

2018-03-27 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

I don't have preferences over names, but I agree with Alex that the option 
should have more detailed description.




Comment at: lib/Format/FormatToken.h:138
+  /// \brief Whether this is a string literal similar to _T("sdfsdf").
+  bool TMacroStringLiteral = false;
+

We don't strictly need this new field. We could do as in the old implementation 
and check if the string prefix is from a T macro in ContinuationIndenter.



Comment at: unittests/Format/FormatTest.cpp:10693
+
+  // FIXME: This is required because parsing a configuration simply overwrites
+  // the first N elements of the list instead of resetting it.

Why is the `FIXME` here? I suggest just use the pattern similar to the other 
cases here and just keep the test with 2 elements:
```
Style.TMacros.clear();
std::vector ExpectedTMacros = {"_T", "myT"};
CHECK_PARSE("TMacros: [_T, myT]", TMacros, ExpectedTMacros);
```


Repository:
  rC Clang

https://reviews.llvm.org/D44765



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


[PATCH] D44882: [clangd] Implementation of workspace/symbol request

2018-03-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clangd/tool/ClangdMain.cpp:105
 
+static llvm::cl::opt LimitWorkspaceSymbolResult(
+"workspace-symbol-limit",

malaperle wrote:
> sammccall wrote:
> > the -completion-limit was mostly to control rollout, I'm not sure this 
> > needs to be a flag. If it does, can we make it the same flag as completions 
> > (and call it -limit or so?)
> I think it's quite similar to "completions", when you type just one letter 
> for example, you can get a lot of results and a lot of JSON output. So it 
> feels like the flag could apply to both completions and workspace symbols. 
> How about -limit-resuts? I think just -limit might be a bit too general as we 
> might want to limit other things.
Can these options be set by LSP initialization options?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44882



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


[PATCH] D44927: Enable msan unconditionally on Linux

2018-03-27 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a subscriber: kcc.
eugenis added a comment.

I too find these checks arbitrary and pointless. @kcc ?


Repository:
  rC Clang

https://reviews.llvm.org/D44927



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


[PATCH] D44747: Set calling convention for CUDA kernel

2018-03-27 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaOverload.cpp:1492
+  Changed = true;
+}
+

yaxunl wrote:
> rjmccall wrote:
> > It's cheaper not to check the CUDA language mode here; pulling the CC out 
> > of the FPT is easy.
> > 
> > Why is this necessary, anyway?  From the spec, it doesn't look to me like 
> > kernel function pointers can be converted to ordinary function pointers.  A 
> > kernel function pointer is supposed to be declared with something like 
> > `__global__ void (*fn)(void)`.  You'll need to change your patch to 
> > SemaType to apply the CC even when compiling for the host, of course.
> > 
> > I was going to say that you should use this CC in your validation that 
> > calls with execution configurations go to kernel functions, but... I can't 
> > actually find where you do that validation.
> > 
> > Do you need these function pointers to be a different size from the host 
> > function pointer?
> In CUDA, `__global__` can only be used with function declaration or 
> definition. Using it in function pointer declaration will result in a 
> warning: 'global' attribute only applies to functions.
> 
> Also, there is this lit test in SemaCUDA:
> 
> ```
> __global__ void kernel() {}
> 
> typedef void (*fn_ptr_t)();
> 
> __host__ fn_ptr_t get_ptr_h() {
>   return kernel;
> }
> 
> ```
> It allows implicit conversion of `__global__ void()` to void(*)(), therefore 
> I need the above change to drop the CUDA kernel calling convention in such 
> implicit conversion.
I see.  I must have mis-read the specification, but I see that the code samples 
I can find online agree with that test case.  So `__global__` function pointers 
are just treated as function pointers, and it's simply undefined behavior if 
you try to call a function pointer that happens to be a kernel without an 
execution configuration, or contrariwise if you use an execution configuration 
to call a function pointer that isn't a kernel.

In that case, I think the best solution is to just immediately strip 
`__global__` from the type of a DRE to a kernel function, since `__global__` 
isn't supposed to be part of the user-facing type system.


https://reviews.llvm.org/D44747



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


[PATCH] D44882: [clangd] Implementation of workspace/symbol request

2018-03-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> Have you considered also allowing '.' and ' ' (space) as separators in the 
> request? Having additional separators doesn't really hurt complexity of the 
> implementation, but allows to switch between tools for different languages 
> easier.

I would suggest allowing patterns containing space to match text without space, 
e.g. pattern `a b` can match text `aB`. The initial character of each word in 
the pattern should be seen as a `Head` position. This behavior matches many 
fuzzy matching plugins used in Emacs and Vim.




Comment at: clangd/SourceCode.cpp:110
+
+llvm::Optional offsetRangeToLocation(SourceManager ,
+   StringRef File,

May I ask a question about the conversion between SourceLocation and LSP 
location? When the document is slightly out of sync with the indexed version, 
what will be returned?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44882



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


[PATCH] D44747: Set calling convention for CUDA kernel

2018-03-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 3 inline comments as done.
yaxunl added inline comments.



Comment at: lib/Sema/SemaOverload.cpp:1492
+  Changed = true;
+}
+

rjmccall wrote:
> It's cheaper not to check the CUDA language mode here; pulling the CC out of 
> the FPT is easy.
> 
> Why is this necessary, anyway?  From the spec, it doesn't look to me like 
> kernel function pointers can be converted to ordinary function pointers.  A 
> kernel function pointer is supposed to be declared with something like 
> `__global__ void (*fn)(void)`.  You'll need to change your patch to SemaType 
> to apply the CC even when compiling for the host, of course.
> 
> I was going to say that you should use this CC in your validation that calls 
> with execution configurations go to kernel functions, but... I can't actually 
> find where you do that validation.
> 
> Do you need these function pointers to be a different size from the host 
> function pointer?
In CUDA, `__global__` can only be used with function declaration or definition. 
Using it in function pointer declaration will result in a warning: 'global' 
attribute only applies to functions.

Also, there is this lit test in SemaCUDA:

```
__global__ void kernel() {}

typedef void (*fn_ptr_t)();

__host__ fn_ptr_t get_ptr_h() {
  return kernel;
}

```
It allows implicit conversion of `__global__ void()` to void(*)(), therefore I 
need the above change to drop the CUDA kernel calling convention in such 
implicit conversion.


https://reviews.llvm.org/D44747



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


[PATCH] D44948: Add diagnostic -Waggregate-ctors, "aggregate type has user-declared constructors"

2018-03-27 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone created this revision.
Herald added a subscriber: cfe-commits.

This new warning diagnoses any aggregate class/struct/union type which has 
user-declared constructors, in order to test the hypothesis that real code does 
not (intentionally) contain such animals.

  

If no real code triggers this diagnostic, then it would be plausible to change 
the definition of "aggregate type" in C++2a so that types triggering this 
diagnostic would no longer be considered aggregate types at all.


Repository:
  rC Clang

https://reviews.llvm.org/D44948

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclCXX.cpp


Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -5907,6 +5907,10 @@
diag::warn_non_virtual_dtor) << Context.getRecordType(Record);
   }
 
+  if (Record->isAggregate() && Record->hasUserDeclaredConstructor()) {
+Diag(Record->getLocation(), 
diag::warn_aggregate_with_user_declared_constructor);
+  }
+
   if (Record->isAbstract()) {
 if (FinalAttr *FA = Record->getAttr()) {
   Diag(Record->getLocation(), diag::warn_abstract_final_class)
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6466,6 +6466,9 @@
 def warn_jump_out_of_seh_finally : Warning<
   "jump out of __finally block has undefined behavior">,
   InGroup>;
+def warn_aggregate_with_user_declared_constructor : Warning<
+  "aggregate type has user-declared constructors">,
+  InGroup;
 def warn_non_virtual_dtor : Warning<
   "%0 has virtual functions but non-virtual destructor">,
   InGroup, DefaultIgnore;
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -99,6 +99,7 @@
 def DeleteIncomplete : DiagGroup<"delete-incomplete">;
 def DeleteNonVirtualDtor : DiagGroup<"delete-non-virtual-dtor">;
 def AbstractFinalClass : DiagGroup<"abstract-final-class">;
+def AggregateCtors : DiagGroup<"aggregate-ctors">;
 
 def CXX11CompatDeprecatedWritableStr :
   DiagGroup<"c++11-compat-deprecated-writable-strings">;


Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -5907,6 +5907,10 @@
diag::warn_non_virtual_dtor) << Context.getRecordType(Record);
   }
 
+  if (Record->isAggregate() && Record->hasUserDeclaredConstructor()) {
+Diag(Record->getLocation(), diag::warn_aggregate_with_user_declared_constructor);
+  }
+
   if (Record->isAbstract()) {
 if (FinalAttr *FA = Record->getAttr()) {
   Diag(Record->getLocation(), diag::warn_abstract_final_class)
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6466,6 +6466,9 @@
 def warn_jump_out_of_seh_finally : Warning<
   "jump out of __finally block has undefined behavior">,
   InGroup>;
+def warn_aggregate_with_user_declared_constructor : Warning<
+  "aggregate type has user-declared constructors">,
+  InGroup;
 def warn_non_virtual_dtor : Warning<
   "%0 has virtual functions but non-virtual destructor">,
   InGroup, DefaultIgnore;
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -99,6 +99,7 @@
 def DeleteIncomplete : DiagGroup<"delete-incomplete">;
 def DeleteNonVirtualDtor : DiagGroup<"delete-non-virtual-dtor">;
 def AbstractFinalClass : DiagGroup<"abstract-final-class">;
+def AggregateCtors : DiagGroup<"aggregate-ctors">;
 
 def CXX11CompatDeprecatedWritableStr :
   DiagGroup<"c++11-compat-deprecated-writable-strings">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44589: [Sema] Make deprecation fix-it replace all multi-parameter ObjC method slots.

2018-03-27 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 139981.
vsapsai added a comment.

- More tweaks. Remove MultiSourceLocation as nobobody, including me, sees much 
value in it.


https://reviews.llvm.org/D44589

Files:
  clang/include/clang/Basic/CharInfo.h
  clang/include/clang/Sema/DelayedDiagnostic.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/DelayedDiagnostic.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/test/SemaObjC/attr-deprecated-replacement-fixit.m
  clang/unittests/Basic/CharInfoTest.cpp

Index: clang/unittests/Basic/CharInfoTest.cpp
===
--- clang/unittests/Basic/CharInfoTest.cpp
+++ clang/unittests/Basic/CharInfoTest.cpp
@@ -432,6 +432,7 @@
   EXPECT_TRUE(isValidIdentifier("z"));
   EXPECT_TRUE(isValidIdentifier("A"));
   EXPECT_TRUE(isValidIdentifier("Z"));
+  EXPECT_TRUE(isValidIdentifier("$", /*AllowDollar=*/true));
 
   // 2 characters, '_' suffix
   EXPECT_FALSE(isValidIdentifier("._"));
@@ -448,6 +449,7 @@
   EXPECT_TRUE(isValidIdentifier("z_"));
   EXPECT_TRUE(isValidIdentifier("A_"));
   EXPECT_TRUE(isValidIdentifier("Z_"));
+  EXPECT_TRUE(isValidIdentifier("$_", /*AllowDollar=*/true));
 
   // 2 characters, '_' prefix
   EXPECT_FALSE(isValidIdentifier("_."));
@@ -464,6 +466,7 @@
   EXPECT_TRUE(isValidIdentifier("_z"));
   EXPECT_TRUE(isValidIdentifier("_A"));
   EXPECT_TRUE(isValidIdentifier("_Z"));
+  EXPECT_TRUE(isValidIdentifier("_$", /*AllowDollar=*/true));
 
   // 3 characters, '__' prefix
   EXPECT_FALSE(isValidIdentifier("__."));
@@ -480,6 +483,7 @@
   EXPECT_TRUE(isValidIdentifier("__z"));
   EXPECT_TRUE(isValidIdentifier("__A"));
   EXPECT_TRUE(isValidIdentifier("__Z"));
+  EXPECT_TRUE(isValidIdentifier("__$", /*AllowDollar=*/true));
 
   // 3 characters, '_' prefix and suffix
   EXPECT_FALSE(isValidIdentifier("_._"));
@@ -496,4 +500,5 @@
   EXPECT_TRUE(isValidIdentifier("_z_"));
   EXPECT_TRUE(isValidIdentifier("_A_"));
   EXPECT_TRUE(isValidIdentifier("_Z_"));
+  EXPECT_TRUE(isValidIdentifier("_$_", /*AllowDollar=*/true));
 }
Index: clang/test/SemaObjC/attr-deprecated-replacement-fixit.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-deprecated-replacement-fixit.m
@@ -0,0 +1,177 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck --implicit-check-not fix-it: %s
+// RUN: cp %s %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -DIGNORE_UNSUCCESSFUL_RENAMES -fixit -x objective-c %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -DIGNORE_UNSUCCESSFUL_RENAMES -Werror -x objective-c %t
+
+#if !__has_feature(attribute_deprecated_with_replacement)
+#error "Missing __has_feature"
+#endif
+
+#if !__has_feature(attribute_availability_with_replacement)
+#error "Missing __has_feature"
+#endif
+
+#define DEPRECATED(replacement) __attribute__((deprecated("message", replacement)))
+
+@protocol SuccessfulMultiParameterRenames
+// expected-note@+1 {{has been explicitly marked deprecated here}}
+- (void)multi:(int)param1 parameter:(int)param2 replacement:(int)param3 DEPRECATED("multi_new:parameter_new:replace_new_ment:");
+- (void)multi_new:(int)param1 parameter_new:(int)param2 replace_new_ment:(int)param3;
+
+// expected-note@+1 {{has been explicitly marked deprecated here}}
+- (void)varArgs:(int)params, ... DEPRECATED("renameVarArgs:");
+- (void)renameVarArgs:(int)params, ...;
+
+// expected-note@+1 {{has been explicitly marked deprecated here}}
+- (void)leadingMinus:(int)param DEPRECATED("-leadingMinusRenamed:");
+- (void)leadingMinusRenamed:(int)param;
+
+// expected-note@+1 {{has been explicitly marked deprecated here}}
+- (void)leadingPlus:(int)param DEPRECATED("+leadingPlusRenamed:");
+- (void)leadingPlusRenamed:(int)param;
+
+// expected-note@+1 {{has been explicitly marked deprecated here}}
+- (void)sourceEmptyName:(int)param1 :(int)param2 DEPRECATED("renameEmptyName:toNonEmpty:");
+- (void)renameEmptyName:(int)param1 toNonEmpty:(int)param2;
+
+// expected-note@+1 {{has been explicitly marked deprecated here}}
+- (void)target:(int)param1 willBecomeEmpty:(int)param2 emptyName:(int)param3 DEPRECATED("target::emptyName:");
+- (void)target:(int)param1 :(int)param2 emptyName:(int)param3;
+
+// expected-note@+1 {{has been explicitly marked deprecated here}}
+- (void)extra:(int)param1 whiteSpace:(int)param2 DEPRECATED("renameExtra:whiteSpace:");
+- (void)renameExtra:(int)param1 whiteSpace:(int)param2;
+
+// Test renaming that was producing valid code earlier is still producing valid
+// code. The difference is that now we detect different number of parameters.
+//
+// expected-note@+1 {{has been explicitly marked deprecated here}}
+- (void)singleArgumentRegression:(int)param DEPRECATED("renameSingleArgument");
+- (void)renameSingleArgument:(int)param;
+@end
+
+void 

r328657 - AMDGPU: Update datalayout for stack alignment

2018-03-27 Thread Matt Arsenault via cfe-commits
Author: arsenm
Date: Tue Mar 27 12:26:51 2018
New Revision: 328657

URL: http://llvm.org/viewvc/llvm-project?rev=328657=rev
Log:
AMDGPU: Update datalayout for stack alignment

Modified:
cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
cfe/trunk/test/CodeGen/target-data.c
cfe/trunk/test/CodeGenOpenCL/amdgpu-env-amdgcn.cl

Modified: cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AMDGPU.cpp?rev=328657=328656=328657=diff
==
--- cfe/trunk/lib/Basic/Targets/AMDGPU.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/AMDGPU.cpp Tue Mar 27 12:26:51 2018
@@ -30,12 +30,12 @@ namespace targets {
 
 static const char *const DataLayoutStringR600 =
 "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
-"-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5";
+"-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5";
 
 static const char *const DataLayoutStringAMDGCN =
 "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32"
 "-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
-"-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5";
+"-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5";
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
 Generic,  // Default

Modified: cfe/trunk/test/CodeGen/target-data.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/target-data.c?rev=328657=328656=328657=diff
==
--- cfe/trunk/test/CodeGen/target-data.c (original)
+++ cfe/trunk/test/CodeGen/target-data.c Tue Mar 27 12:26:51 2018
@@ -124,20 +124,20 @@
 
 // RUN: %clang_cc1 -triple r600-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=R600
-// R600: target datalayout = 
"e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5"
+// R600: target datalayout = 
"e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
 
 // RUN: %clang_cc1 -triple r600-unknown -target-cpu cayman -o - -emit-llvm %s \
 // RUN: | FileCheck %s -check-prefix=R600D
-// R600D: target datalayout = 
"e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5"
+// R600D: target datalayout = 
"e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
 
 // RUN: %clang_cc1 -triple amdgcn-unknown -target-cpu hawaii -o - -emit-llvm 
%s \
 // RUN: | FileCheck %s -check-prefix=R600SI
-// R600SI: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5"
+// R600SI: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
 
 // Test default -target-cpu
 // RUN: %clang_cc1 -triple amdgcn-unknown -o - -emit-llvm %s \
 // RUN: | FileCheck %s -check-prefix=R600SIDefault
-// R600SIDefault: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5"
+// R600SIDefault: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
 
 // RUN: %clang_cc1 -triple arm64-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=AARCH64

Modified: cfe/trunk/test/CodeGenOpenCL/amdgpu-env-amdgcn.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgpu-env-amdgcn.cl?rev=328657=328656=328657=diff
==
--- cfe/trunk/test/CodeGenOpenCL/amdgpu-env-amdgcn.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/amdgpu-env-amdgcn.cl Tue Mar 27 12:26:51 2018
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -O0 -triple amdgcn -emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 %s -O0 -triple amdgcn---opencl -emit-llvm -o - | FileCheck 
%s
 
-// CHECK: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5"
+// CHECK: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
 void foo(void) {}


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


[PATCH] D44947: [Driver] Add fuzzer-no-link into the list of supported Fuchsia sanitizers

2018-03-27 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: mcgrathr, aarongreen.
Herald added a subscriber: cfe-commits.

This is needed in addition to fuzzer in order to use libFuzzer.


Repository:
  rC Clang

https://reviews.llvm.org/D44947

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


Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -280,6 +280,7 @@
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::FuzzerNoLink;
   Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;


Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -280,6 +280,7 @@
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::FuzzerNoLink;
   Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44330: CMake option to allow enabling experimental new pass manager by default

2018-03-27 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/CMakeLists.txt:215
 
+set(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER FALSE CACHE BOOL
+  "Enable the experimental new pass manager by default.")

chandlerc wrote:
> Does it make sense to put the word `DEFAULT` into the variable name? I don't 
> feel strongly either way.
I was following the `ENABLE_X86_RELAX_RELOCATIONS` above which is a similar 
flag in terms of its effect on the driver. Would you prefer 
`ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER_BY_DEFAULT`? It's more descriptive but 
also rather long.


Repository:
  rC Clang

https://reviews.llvm.org/D44330



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-03-27 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang-doc/BitcodeWriter.h:129
 // Check that the static size is large-enough.
 assert(Record.capacity() > BitCodeConstants::RecordSize);
   }

juliehockett wrote:
> lebedev.ri wrote:
> > Isn't that the opposite of what was that assert supposed to do?
> > It would have been better to just `// disable` it, and add a `FIXME` note.
> I'm not sure I'm understanding you -- my understanding was that it existed to 
> check that the record size was large enough.
https://reviews.llvm.org/D41102?id=136520#inline-384087
```
#ifndef NDEBUG // Don't want explicit dtor unless needed
~ClangDocBitcodeWriter() {
  // Check that the static size is large-enough.
  assert(Record.capacity() == BitCodeConstants::RecordSize);
}
#endif
```
I.e. it checked that it still only had the static size, and did not transform 
into normal `vector` with data stored on heap-allocated buffer.


https://reviews.llvm.org/D43341



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


[PATCH] D44723: Set dso_local when clearing dllimport

2018-03-27 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm

I'd add more tests but I can't think of ways to remove the dll attributes, only 
to flip them.

Do we already have dso_local tests for this similar case:

  __declspec(dllimport) void f();
  void g() { f(); } // use it
  void f() { }

It flips from dllimport to dllexport.


https://reviews.llvm.org/D44723



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-03-27 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/BitcodeReader.cpp:27
+  assert(Record[0] == 20);
+  for (int I = 0, E = Record[0]; I < E; ++I)
+Field[I] = Record[I + 1];

lebedev.ri wrote:
> Ok, i don't understand what is going on here.
> Where is this `E` defined?
> This looks like `[0]` is the number of elements to read (always 20, sha1 
> blob?),
> and it copies Record[1]..Record[20] to Field[0]..Field[19] ?
> I think this can/should be rewritten clearer..
`Record[0]` holds the size of the array -- in this case, 20 -- in the bitstream 
representation of the array (see the array section [[ 
https://llvm.org/docs/BitCodeFormat.html#define-abbrev-encoding | here ]]). So, 
yes, it copies Record[1]...[20] to Field[0]...[19]. Not sure how that can be 
rewritten more clearly, but I'll add a clarifying comment!



Comment at: clang-doc/BitcodeWriter.h:129
 // Check that the static size is large-enough.
 assert(Record.capacity() > BitCodeConstants::RecordSize);
   }

lebedev.ri wrote:
> Isn't that the opposite of what was that assert supposed to do?
> It would have been better to just `// disable` it, and add a `FIXME` note.
I'm not sure I'm understanding you -- my understanding was that it existed to 
check that the record size was large enough.



Comment at: clang-doc/Reducer.cpp:18
+std::unique_ptr mergeInfos(tooling::ToolResults *Results) {
+  std::unique_ptr UniqueInfos = llvm::make_unique();
+  bool Err = false;

lebedev.ri wrote:
> I can see that you may `return nullptr;` in case of error here, thus it's 
> `std::unique_ptr<>`
> `InfoSet` internally is just a few `std::vector<>`s, so it should 
> `std::move()` efficiently.
> I'm wondering if `llvm::Optional` would work too?
Doesn't `llvm::Optional` imply that it *could* validly not exist though? This 
is trying to express here that that isn't a valid state.



Comment at: clang-doc/Representation.h:135
   Info() = default;
-  Info(Info &) : Description(std::move(Other.Description)) {}
-  virtual ~Info() = default;
+  Info(Info &)
+  : USR(Other.USR), Name(Other.Name), 
Namespace(std::move(Other.Namespace)),

lebedev.ri wrote:
> Why is the move constructor explicitly defined?
> Unless i'm missing something, the default one would do exactly the same.
> https://godbolt.org/g/XqsRuX
It's there (as is the CommentInfo one) because otherwise it was throwing 
errors. It appears that a copy constructor is called somewhere if this isn't 
specified.


https://reviews.llvm.org/D43341



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-03-27 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 139972.
juliehockett marked 4 inline comments as done.
juliehockett added a comment.

Small fixes to address comments


https://reviews.llvm.org/D43341

Files:
  clang-doc/BitcodeReader.cpp
  clang-doc/BitcodeReader.h
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/Reducer.cpp
  clang-doc/Reducer.h
  clang-doc/Representation.cpp
  clang-doc/Representation.h
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/bc-comment.cpp
  test/clang-doc/bc-namespace.cpp
  test/clang-doc/bc-record.cpp

Index: test/clang-doc/bc-record.cpp
===
--- /dev/null
+++ test/clang-doc/bc-record.cpp
@@ -0,0 +1,178 @@
+// This test requires Linux due to the system-dependent USR for the
+// inner class in function H.
+// REQUIRES: system-linux
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/docs.bc --dump | FileCheck %s
+
+union A { int X; int Y; };
+
+enum B { X, Y };
+
+enum class Bc { A, B };
+
+struct C { int i; };
+
+class D {};
+
+class E {
+public:
+  E() {}
+  ~E() {}
+
+protected:
+  void ProtectedMethod();
+};
+
+void E::ProtectedMethod() {}
+
+class F : virtual private D, public E {};
+
+class X {
+  class Y {};
+};
+
+void H() {
+  class I {};
+}
+
+// CHECK: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'E'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'void'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '~E'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'void'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'ProtectedMethod'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'void'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'H'
+  // CHECK-NEXT:  blob data = '3433664532ABFCC39301646A10E768C1882BF194'
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'void'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'A'
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'int'
+// CHECK-NEXT:  blob data = 'A::X'
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'int'
+// CHECK-NEXT:  blob data = 'A::Y'
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'C'
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'int'
+// CHECK-NEXT:  blob data = 'C::i'
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'D'
+  // CHECK-NEXT:  blob data = 'E3B54702FABFF4037025BA194FC27C47006330B5'
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'E'
+  // CHECK-NEXT:  blob data = 'E3B54702FABFF4037025BA194FC27C47006330B5'
+  // CHECK-NEXT:  blob data = 'DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4'
+  // CHECK-NEXT:  blob data = 'DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4'
+  // CHECK-NEXT:  blob data = 'BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17'
+  // CHECK-NEXT:  blob data = 'BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17'
+  // CHECK-NEXT:  blob data = '5093D428CDC62096A67547BA52566E4FB9404EEE'
+  // CHECK-NEXT:  blob data = '5093D428CDC62096A67547BA52566E4FB9404EEE'
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'F'
+  // CHECK-NEXT:  blob data = '{{.*}}'
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT:  blob data = '0921737541208B8FA9BB42B60F78AC1D779AA054'
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'X'
+  // CHECK-NEXT:  blob data = 

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

2018-03-27 Thread Matthew Voss via Phabricator via cfe-commits
ormris added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:2992
+  std::string NameString = Name.str();
+  llvm::raw_string_ostream ParameterizedName(NameString);
+  ParameterizedName << "<";

JDevlieghere wrote:
> Why not use Name.str() directly?
I got "error: invalid initialization of non-const reference ... from rvalue 
...". Using NameString fixed the issue.


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] D44882: [clangd] Implementation of workspace/symbol request

2018-03-27 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle updated this revision to Diff 139968.
malaperle marked 4 inline comments as done.
malaperle added a comment.

Split the patch so that this part only has the workspace/symbol part
and the index model will be updated separately.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44882

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/FindSymbols.cpp
  clangd/FindSymbols.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  clangd/XRefs.cpp
  clangd/index/SymbolCollector.cpp
  clangd/tool/ClangdMain.cpp
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  unittests/clangd/CMakeLists.txt
  unittests/clangd/FindSymbolsTests.cpp
  unittests/clangd/SyncAPI.cpp
  unittests/clangd/SyncAPI.h

Index: unittests/clangd/SyncAPI.h
===
--- unittests/clangd/SyncAPI.h
+++ unittests/clangd/SyncAPI.h
@@ -41,6 +41,10 @@
 
 std::string runDumpAST(ClangdServer , PathRef File);
 
+llvm::Expected
+runWorkspaceSymbols(ClangdServer , StringRef Query,
+const WorkspaceSymbolOptions );
+
 } // namespace clangd
 } // namespace clang
 
Index: unittests/clangd/SyncAPI.cpp
===
--- unittests/clangd/SyncAPI.cpp
+++ unittests/clangd/SyncAPI.cpp
@@ -110,5 +110,13 @@
   return std::move(*Result);
 }
 
+llvm::Expected
+runWorkspaceSymbols(ClangdServer , StringRef Query,
+const WorkspaceSymbolOptions ) {
+  llvm::Optional> Result;
+  Server.workspaceSymbols(Query, Opts, capture(Result));
+  return std::move(*Result);
+}
+
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/FindSymbolsTests.cpp
===
--- /dev/null
+++ unittests/clangd/FindSymbolsTests.cpp
@@ -0,0 +1,380 @@
+//===-- FindSymbolsTests.cpp -*- C++ -*===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+#include "Annotations.h"
+#include "ClangdServer.h"
+#include "FindSymbols.h"
+#include "SyncAPI.h"
+#include "TestFS.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+
+void PrintTo(const SymbolInformation , std::ostream *O) {
+  llvm::raw_os_ostream OS(*O);
+  OS << I.containerName << I.name << " - " << toJSON(I);
+}
+
+namespace {
+
+using ::testing::AllOf;
+using ::testing::AnyOf;
+using ::testing::ElementsAre;
+using ::testing::IsEmpty;
+using ::testing::UnorderedElementsAre;
+
+class IgnoreDiagnostics : public DiagnosticsConsumer {
+  void onDiagnosticsReady(PathRef File,
+  std::vector Diagnostics) override {}
+};
+
+// GMock helpers for matching SymbolInfos items.
+MATCHER_P(Named, Name, "") { return arg.name == Name; }
+MATCHER_P(InContainer, ContainerName, "") {
+  return arg.containerName == ContainerName;
+}
+MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
+
+class WorkspaceSymbolsTest : public ::testing::Test {
+protected:
+  std::unique_ptr FSProvider;
+  std::unique_ptr CDB;
+  std::unique_ptr DiagConsumer;
+  std::unique_ptr Server;
+  std::unique_ptr Opts;
+
+  virtual void SetUp() override {
+FSProvider = llvm::make_unique();
+CDB = llvm::make_unique();
+DiagConsumer = llvm::make_unique();
+auto ServerOpts = ClangdServer::optsForTest();
+ServerOpts.BuildDynamicSymbolIndex = true;
+Server = llvm::make_unique(*CDB, *FSProvider, *DiagConsumer,
+ ServerOpts);
+Opts = llvm::make_unique();
+  }
+
+  std::vector getSymbols(StringRef Query) {
+EXPECT_TRUE(Server->blockUntilIdleForTest()) << "Waiting for preamble";
+auto SymbolInfos = runWorkspaceSymbols(*Server, Query, *Opts);
+EXPECT_TRUE(bool(SymbolInfos)) << "workspaceSymbols returned an error";
+return *SymbolInfos;
+  }
+
+  void addFile(StringRef FileName, StringRef Contents) {
+auto Path = testPath(FileName);
+FSProvider->Files[Path] = Contents;
+Server->addDocument(Path, Contents);
+  }
+};
+
+} // namespace
+
+TEST_F(WorkspaceSymbolsTest, NoMacro) {
+  addFile("foo.cpp", R"cpp(
+  #define MACRO X
+  )cpp");
+
+  // Macros are not in the index.
+  EXPECT_THAT(getSymbols("macro"), IsEmpty());
+}
+
+TEST_F(WorkspaceSymbolsTest, NoLocals) {
+  addFile("foo.cpp", R"cpp(
+  void test() {
+struct LocalClass {};
+int local_var;
+  })cpp");
+  EXPECT_THAT(getSymbols("local_var"), IsEmpty());
+  

[PATCH] D44916: [Sema] Avoid crash for category implementation without interface

2018-03-27 Thread Shoaib Meenai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328654: [Sema] Avoid crash for category implementation 
without interface (authored by smeenai, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D44916

Files:
  cfe/trunk/lib/Sema/SemaExprMember.cpp
  cfe/trunk/test/SemaObjC/undef-class-property-error.m


Index: cfe/trunk/test/SemaObjC/undef-class-property-error.m
===
--- cfe/trunk/test/SemaObjC/undef-class-property-error.m
+++ cfe/trunk/test/SemaObjC/undef-class-property-error.m
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@implementation I (C) // expected-error {{cannot find interface declaration 
for 'I'}}
+
++ (void)f {
+  self.m; // expected-error {{member reference base type 'Class' is not a 
structure or union}}
+}
+
+@end
Index: cfe/trunk/lib/Sema/SemaExprMember.cpp
===
--- cfe/trunk/lib/Sema/SemaExprMember.cpp
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp
@@ -1568,6 +1568,9 @@
   // Also must look for a getter name which uses property syntax.
   Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
   ObjCInterfaceDecl *IFace = MD->getClassInterface();
+  if (!IFace)
+goto fail;
+
   ObjCMethodDecl *Getter;
   if ((Getter = IFace->lookupClassMethod(Sel))) {
 // Check the use of this method.


Index: cfe/trunk/test/SemaObjC/undef-class-property-error.m
===
--- cfe/trunk/test/SemaObjC/undef-class-property-error.m
+++ cfe/trunk/test/SemaObjC/undef-class-property-error.m
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@implementation I (C) // expected-error {{cannot find interface declaration for 'I'}}
+
++ (void)f {
+  self.m; // expected-error {{member reference base type 'Class' is not a structure or union}}
+}
+
+@end
Index: cfe/trunk/lib/Sema/SemaExprMember.cpp
===
--- cfe/trunk/lib/Sema/SemaExprMember.cpp
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp
@@ -1568,6 +1568,9 @@
   // Also must look for a getter name which uses property syntax.
   Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
   ObjCInterfaceDecl *IFace = MD->getClassInterface();
+  if (!IFace)
+goto fail;
+
   ObjCMethodDecl *Getter;
   if ((Getter = IFace->lookupClassMethod(Sel))) {
 // Check the use of this method.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44882: [clangd] Implementation of workspace/symbol request

2018-03-27 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle marked 9 inline comments as done.
malaperle added a comment.

In https://reviews.llvm.org/D44882#1048355, @sammccall wrote:

> Can we split this patch up (it's pretty large anyway) and land the 
> `workspaceSymbols` implementation first, without changing the indexer 
> behavior?
>
> I think the indexer changes are in the right direction, but I think 
> "ForCompletion" isn't quite enough metadata, and don't want to block 
> everything on that.


Sounds good. ForCompletion was more of a short term hack in my mind, we can try 
to split it and make proper metadata.

>> We have a lot more features in mind that will make the index much bigger, 
>> like adding all occurrences (maybe not in the current YAML though).
> 
> (tangential)
>  FWIW, I think *that* might be a case where we want quite a different API - I 
> think this is a file-major index operation (handful of results per file) 
> rather than a symbol-major one (results per symbol is essentially unbounded, 
> e.g. `std::string`). At the scale of google's internal codebase, this means 
> we need a different backend, and this may be the case for large open-source 
> codebases too (I know chromium hits scaling issues with indexers they try). 
>  There are also other operations where results are files rather than symbols: 
> which files include file x, etc.

Yeah, there needs to be an API to fetch things per file, such as the 
dependencies and the occurrences it contains (for updating when the file is 
deleted, etc). I'm not sure there needs to be an API that queries a file for a 
given USR though, I think that could be transparent to the caller and an 
implementation detail. The results could be grouped by file though. Good 
discussion for future patches :)

>> But having options to control the amount of information indexed sounds good 
>> to me as there can be a lot of different project sizes and there can be 
>> different tradeoffs. I had in mind to an option for including/excluding the 
>> occurrences because without them, you lose workspace/references, call 
>> hierarchy, etc, but you still have code completion and workspace/symbol, 
>> document/symbol, etc while making the index much smaller. But more options 
>> sounds good.
> 
> If we add options, someone has to actually set them.
>  Anything that's too big for google's internal index or similar can be 
> filtered out in the wrapping code (mapreduce) if the indexer exposes enough 
> information to do so.
>  We shouldn't have problems with the in-memory dynamic index.
>  Features that are off in the default static indexer configuration won't end 
> up getting used much.

I think everything should be ON by default but we can run into issues that the 
user wants to reduce index size and help indexing speed. We had such options in 
CDT since there are quite a few things that can make it big (macro expansion 
steps, all references, etc). But this can be added as needed later.

> So I can see a use for filters where the command-line indexer (YAML) would 
> run too slow otherwise, but a) let's cross that bridge when we come to it

Sounds good.

In https://reviews.llvm.org/D44882#1049007, @ilya-biryukov wrote:

> >>> - Current `fuzzyFind` implementation can only match qualifiers strictly 
> >>> (i.e. st::vector won't match std::vector). Should we look into allowing 
> >>> fuzzy matches for this feature?  (not in this patch, rather in the long 
> >>> term).
> >> 
> >> I'm not sure, I'm thinking there should be a balance between how fuzzy it 
> >> it and how much noise it generates. Right now I find it a bit too fuzzy 
> >> since when I type "Draft" (to find DraftMgr), it picks up things like 
> >> DocumentRangeFormattingParams. Adding fuzziness to the namespace would 
> >> make this worse. Maybe with improved scoring it won't matter too much? 
> >> I'll try FuzzyMatcher and see.
> > 
> > +1, I think experience with `workspaceSymbols` will help us answer this 
> > question.
>
> I was using an IDE that had fuzzy find for an equivalent of 
> `workspaceSymbols` and found it to be an amazing experience. And having 
> consistent behavior between different features is really nice.
>  Good ranking is a key to it being useful, though. If when typing `Draft` you 
> get `DocumentRangeFormattingParams` ranked higher than `DraftMgr` that's a 
> bug in FuzzyMatcher. If you have some not-very-nice results at the end of the 
> list, this shouldn't be a problem in most cases.
>
> I'm highly in favor of enabling fuzzy matching for `workspaceSymbols`.


I think it will be fine once we address the bug(s). As long as the exact 
matches are always first then there's no problem.




Comment at: clangd/ClangdLSPServer.cpp:99
   
Params.capabilities.textDocument.completion.completionItem.snippetSupport;
+  if (Params.capabilities.workspace && Params.capabilities.workspace->symbol &&
+  Params.capabilities.workspace->symbol->symbolKind)

sammccall wrote:
> This is the analogue to the 

r328654 - [Sema] Avoid crash for category implementation without interface

2018-03-27 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Tue Mar 27 11:58:28 2018
New Revision: 328654

URL: http://llvm.org/viewvc/llvm-project?rev=328654=rev
Log:
[Sema] Avoid crash for category implementation without interface

When we have a category implementation without a corresponding interface
(which is an error by itself), semantic checks for property accesses
will attempt to access a null interface declaration and then segfault.
Error out in such cases instead.

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

Added:
cfe/trunk/test/SemaObjC/undef-class-property-error.m
Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=328654=328653=328654=diff
==
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Tue Mar 27 11:58:28 2018
@@ -1568,6 +1568,9 @@ static ExprResult LookupMemberExpr(Sema
   // Also must look for a getter name which uses property syntax.
   Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
   ObjCInterfaceDecl *IFace = MD->getClassInterface();
+  if (!IFace)
+goto fail;
+
   ObjCMethodDecl *Getter;
   if ((Getter = IFace->lookupClassMethod(Sel))) {
 // Check the use of this method.

Added: cfe/trunk/test/SemaObjC/undef-class-property-error.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/undef-class-property-error.m?rev=328654=auto
==
--- cfe/trunk/test/SemaObjC/undef-class-property-error.m (added)
+++ cfe/trunk/test/SemaObjC/undef-class-property-error.m Tue Mar 27 11:58:28 
2018
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@implementation I (C) // expected-error {{cannot find interface declaration 
for 'I'}}
+
++ (void)f {
+  self.m; // expected-error {{member reference base type 'Class' is not a 
structure or union}}
+}
+
+@end


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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-03-27 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

It's surprisingly difficult to review this :/
Just by itself the logic is simple, but the amount of blocks/records/record 
types is kinda demoralizing.
I really hope it will be possible to somehow tablegen this later.




Comment at: clang-doc/BitcodeReader.cpp:363
+CommentInfo &
+ClangDocBitcodeReader::getCommentInfo(std::unique_ptr ) {
+  I->Children.emplace_back(llvm::make_unique());

Hmm, why does this function exist?
The only difference from the previous one is the `std::unique_ptr<>`.



Comment at: clang-doc/BitcodeReader.cpp:488
+  // Sniff for the signature.
+  if (Stream.Read(8) != 'D' || Stream.Read(8) != 'O' || Stream.Read(8) != 'C' 
||
+  Stream.Read(8) != 'S')

This signature should be in one place (header?), and then just used here and in 
`ClangDocBitcodeWriter::emitHeader()`



Comment at: clang-doc/BitcodeWriter.cpp:537
 
+void ClangDocBitcodeWriter::emitInfoSet(InfoSet ) {
+  for (const auto  : ISet.getNamespaceInfos()) emitBlock(I);

It should be `void ClangDocBitcodeWriter::emitInfoSet(const InfoSet ) {` 
then.



Comment at: clang-doc/BitcodeWriter.h:129
 // Check that the static size is large-enough.
 assert(Record.capacity() > BitCodeConstants::RecordSize);
   }

Isn't that the opposite of what was that assert supposed to do?
It would have been better to just `// disable` it, and add a `FIXME` note.



Comment at: clang-doc/tool/ClangDocMain.cpp:138
+llvm::outs() << "Writing intermediate results...\n";
+SmallString<4098> Buffer;
+llvm::BitstreamWriter Stream(Buffer);

`4096`?


https://reviews.llvm.org/D43341



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


[PATCH] D43871: [modules] No longer include stdlib.h from mm_malloc.h.

2018-03-27 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor updated this revision to Diff 139963.
teemperor added a comment.

- Added more test cases for reverse include order and clang modules.


https://reviews.llvm.org/D43871

Files:
  lib/Headers/mm_malloc.h
  lib/Sema/SemaExceptionSpec.cpp
  test/CXX/except/except.spec/Inputs/clang/mm_malloc.h
  test/CXX/except/except.spec/Inputs/clang/module.modulemap
  test/CXX/except/except.spec/Inputs/libc/module.modulemap
  test/CXX/except/except.spec/Inputs/libc/stdlib.h
  test/CXX/except/except.spec/libc-empty-except.cpp

Index: test/CXX/except/except.spec/libc-empty-except.cpp
===
--- /dev/null
+++ test/CXX/except/except.spec/libc-empty-except.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -std=c++11 -isystem %S/Inputs/clang -internal-externc-isystem %S/Inputs/libc -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -isystem %S/Inputs/clang -internal-externc-isystem %S/Inputs/libc -fexceptions -fcxx-exceptions -fsyntax-only -verify -DREVERSE %s
+// One of the headers is in a user include, so our redeclaration should fail.
+// RUN: not %clang_cc1 -std=c++11 -I %S/Inputs/clang -internal-externc-isystem %S/Inputs/libc -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
+// RUN: not %clang_cc1 -std=c++11 -isystem %S/Inputs/clang -I %S/Inputs/libc -fexceptions -fcxx-exceptions -fsyntax-only -verify -DREVERSE %s
+
+// The same test cases again with enabled modules.
+// The modules cases *all* pass because we marked both as [system].
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fimplicit-module-maps -fmodules-cache-path=%t \
+// RUN:-std=c++11 -isystem %S/Inputs/clang -internal-externc-isystem %S/Inputs/libc -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fimplicit-module-maps -fmodules-cache-path=%t \
+// RUN:-std=c++11 -isystem %S/Inputs/clang -internal-externc-isystem %S/Inputs/libc -fexceptions -fcxx-exceptions -fsyntax-only -verify -DREVERSE %s
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fimplicit-module-maps -fmodules-cache-path=%t \
+// RUN:-std=c++11 -I %S/Inputs/clang -internal-externc-isystem %S/Inputs/libc -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fimplicit-module-maps -fmodules-cache-path=%t \
+// RUN:-std=c++11 -isystem %S/Inputs/clang -I %S/Inputs/libc -fexceptions -fcxx-exceptions -fsyntax-only -verify -DREVERSE %s
+
+// expected-no-diagnostics
+#ifdef REVERSE
+#include "mm_malloc.h"
+#include "stdlib.h"
+#else
+#include "mm_malloc.h"
+#include "stdlib.h"
+#endif
+
+void f() {
+  free(nullptr);
+}
Index: test/CXX/except/except.spec/Inputs/libc/stdlib.h
===
--- /dev/null
+++ test/CXX/except/except.spec/Inputs/libc/stdlib.h
@@ -0,0 +1,2 @@
+// declare free like glibc with a empty exception specifier.
+extern "C" void free(void *ptr) throw();
Index: test/CXX/except/except.spec/Inputs/libc/module.modulemap
===
--- /dev/null
+++ test/CXX/except/except.spec/Inputs/libc/module.modulemap
@@ -0,0 +1,4 @@
+module libc [system] {
+  header "stdlib.h"
+  export *
+}
Index: test/CXX/except/except.spec/Inputs/clang/module.modulemap
===
--- /dev/null
+++ test/CXX/except/except.spec/Inputs/clang/module.modulemap
@@ -0,0 +1,4 @@
+module builtin [system] {
+  header "mm_malloc.h"
+  export *
+}
Index: test/CXX/except/except.spec/Inputs/clang/mm_malloc.h
===
--- /dev/null
+++ test/CXX/except/except.spec/Inputs/clang/mm_malloc.h
@@ -0,0 +1,3 @@
+// missing throw() is allowed in this case as we are in a system header.
+// This is a redeclaration possibly from glibc.
+extern "C" void free(void *ptr);
Index: lib/Sema/SemaExceptionSpec.cpp
===
--- lib/Sema/SemaExceptionSpec.cpp
+++ lib/Sema/SemaExceptionSpec.cpp
@@ -213,6 +213,7 @@
 const FunctionProtoType *New, SourceLocation NewLoc,
 bool *MissingExceptionSpecification = nullptr,
 bool *MissingEmptyExceptionSpecification = nullptr,
+bool *ExtraEmptyExceptionSpecification = nullptr,
 bool AllowNoexceptAllMatchWithNoSpec = false, bool IsOperatorNew = false);
 
 /// Determine whether a function has an implicitly-generated exception
@@ -236,6 +237,15 @@
   return !Ty->hasExceptionSpec();
 }
 
+/// Returns true if the given function is a function/builtin with C linkage
+/// and from a system header.
+static bool isCSystemFuncOrBuiltin(FunctionDecl *D, ASTContext ) {
+  return (D->getLocation().isInvalid() ||
+  

[PATCH] D35068: [analyzer] Detect usages of unsafe I/O functions

2018-03-27 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

@koldaniel Have you evaluated this checker? On which codebases? Were the 
warnings real security issues, or were they mostly spurious? The code seems 
fine, but I'm not sure whether it should be in `security` or in `alpha`.


https://reviews.llvm.org/D35068



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


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

2018-03-27 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 139961.
Quuxplusone edited the summary of this revision.
Quuxplusone added a comment.

Rebased on master.  AFAIK this is ready to go and I just need someone to land 
it for me... @rtrieu ping?

I believe the PR summary would be suitable as a commit message.


Repository:
  rC Clang

https://reviews.llvm.org/D43322

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/warn-return-std-move.cpp

Index: test/SemaCXX/warn-return-std-move.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-return-std-move.cpp
@@ -0,0 +1,334 @@
+// RUN: %clang_cc1 -fsyntax-only -Wreturn-std-move -Wreturn-std-move-in-cxx11 -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wreturn-std-move -Wreturn-std-move-in-cxx11 -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %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 &(T &);
+} // namespace foo
+} // namespace std
+
+struct Instrument {
+Instrument() {}
+Instrument(Instrument&&) { /* MOVE */ }
+Instrument(const Instrument&) { /* COPY */ }
+};
+struct ConvertFromBase { Instrument i; };
+struct ConvertFromDerived { Instrument i; };
+struct Base {
+Instrument i;
+operator ConvertFromBase() const& { return ConvertFromBase{i}; }
+operator ConvertFromBase() && { return ConvertFromBase{std::move(i)}; }
+};
+struct Derived : public Base {
+operator ConvertFromDerived() const& { return ConvertFromDerived{i}; }
+operator ConvertFromDerived() && { return ConvertFromDerived{std::move(i)}; }
+};
+struct ConstructFromBase {
+Instrument i;
+ConstructFromBase(const Base& b): i(b.i) {}
+ConstructFromBase(Base&& b): i(std::move(b.i)) {}
+};
+struct ConstructFromDerived {
+Instrument i;
+ConstructFromDerived(const Derived& d): i(d.i) {}
+ConstructFromDerived(Derived&& d): i(std::move(d.i)) {}
+};
+
+struct TrivialInstrument {
+int i = 42;
+};
+struct ConvertFromTrivialBase { TrivialInstrument i; };
+struct ConvertFromTrivialDerived { TrivialInstrument i; };
+struct TrivialBase {
+TrivialInstrument i;
+operator ConvertFromTrivialBase() const& { return ConvertFromTrivialBase{i}; }
+operator ConvertFromTrivialBase() && { return ConvertFromTrivialBase{std::move(i)}; }
+};
+struct TrivialDerived : public TrivialBase {
+operator ConvertFromTrivialDerived() const& { return ConvertFromTrivialDerived{i}; }
+operator ConvertFromTrivialDerived() && { return ConvertFromTrivialDerived{std::move(i)}; }
+};
+struct ConstructFromTrivialBase {
+TrivialInstrument i;
+ConstructFromTrivialBase(const TrivialBase& b): i(b.i) {}
+ConstructFromTrivialBase(TrivialBase&& b): i(std::move(b.i)) {}
+};
+struct ConstructFromTrivialDerived {
+TrivialInstrument i;
+ConstructFromTrivialDerived(const TrivialDerived& d): i(d.i) {}
+ConstructFromTrivialDerived(TrivialDerived&& d): i(std::move(d.i)) {}
+};
+
+Derived test1() {
+Derived d1;
+return d1;  // ok
+}
+Base test2() {
+Derived d2;
+return d2;  // e1
+// expected-warning@-1{{will be copied despite being returned by name}}
+// expected-note@-2{{to avoid copying}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
+}
+ConstructFromDerived test3() {
+Derived d3;
+return d3;  // e2-cxx11
+// expected-warning@-1{{would have been copied despite being returned by name}}
+// expected-note@-2{{to avoid copying on older compilers}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+}
+ConstructFromBase test4() {
+Derived d4;
+return d4;  // e3
+// expected-warning@-1{{will be copied despite being returned by name}}
+// expected-note@-2{{to avoid copying}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)"
+}
+ConvertFromDerived test5() {
+Derived d5;
+return d5;  // e4
+// expected-warning@-1{{will be copied despite being returned by name}}
+// expected-note@-2{{to avoid copying}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)"
+}
+ConvertFromBase test6() {
+Derived d6;
+return d6;  // e5
+// expected-warning@-1{{will be copied despite being returned by name}}
+// expected-note@-2{{to avoid copying}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d6)"
+}
+
+// These test cases should not produce the warning.
+Derived ok1() { Derived d; return d; }
+Base ok2() { Derived d; return static_cast(d); }
+ConstructFromDerived ok3() { Derived d; return static_cast(d); }

[PATCH] D44888: [RISCV] Default enable linker relaxation and add -mno-relax flag to disable it

2018-03-27 Thread Ana Pazos via Phabricator via cfe-commits
apazos added inline comments.



Comment at: include/clang/Driver/Options.td:1874
 
+def mno_relax : Flag<["-"], "mno-relax">,
+Group;

I think we should define both -mrelax and -mno-relax flags



Comment at: lib/Driver/ToolChains/Arch/RISCV.cpp:55
   }
+  if (Args.getLastArg(options::OPT_mno_relax)) {
+// Not passing relax.

If we add both mrelax and mno-relax flags, we need to update this logic...

// -mrelax is default, unless -mno-relax is specified.
bool Relax = true;
if (auto *A = Args.getLastArg(options::OPT_mrelax, options::OPT_mno_relax))
  if(A->getOption().matches(options::OPT_mno_relax))
Relax = false;
if (Relax)
 Features.push_back("+relax");




Repository:
  rC Clang

https://reviews.llvm.org/D44888



___
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-03-27 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

I think doing this here can result in double-warning if the overload resolves 
to a builtin operator.  Now, it might not actually be possible for that to 
combine with the requirements for self-assignment, but still, I think the right 
place to diagnose this for C++ is the same place we call DiagnoseSelfMove in 
CreateOverloadedBinOp.

Can CheckIdentityFieldAssignment just be integrated with DiagnoseSelfAssignment 
so that callers don't need to do call both?


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: [clang-tools-extra] r328500 - [clangd] Support incremental document syncing

2018-03-27 Thread Reid Kleckner via cfe-commits
One of these new tests does not pass on Windows due to assumptions about
absolute path structure. The FileCheck output seems self-explanatory:

$ "FileCheck" "-strict-whitespace"
"C:\b\slave\clang-x86-windows-msvc2015\clang-x86-windows-msvc2015\llvm\tools\clang\tools\extra\test\clangd\textdocument-didchange-fail.test"
# command stderr:
C:\b\slave\clang-x86-windows-msvc2015\clang-x86-windows-msvc2015\llvm\tools\clang\tools\extra\test\clangd\textdocument-didchange-fail.test:22:20:
error: expected string not found in input
# CHECK-NEXT:  "uri": "file:///clangd-test/main.cpp"
   ^
:68:7: note: scanning from here
  "uri": "file:///C%3a/clangd-test/main.cpp"

I committed a speculative fix for this in r328645, hopefully it does the
job.

On Mon, Mar 26, 2018 at 7:32 PM Simon Marchi via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: simark
> Date: Mon Mar 26 07:41:40 2018
> New Revision: 328500
>
> URL: http://llvm.org/viewvc/llvm-project?rev=328500=rev
> Log:
> [clangd] Support incremental document syncing
>
> Summary:
> This patch adds support for incremental document syncing, as described
> in the LSP spec.  The protocol specifies ranges in terms of Position (a
> line and a character), and our drafts are stored as plain strings.  So I
> see two things that may not be super efficient for very large files:
>
> - Converting a Position to an offset (the positionToOffset function)
>   requires searching for end of lines until we reach the desired line.
> - When we update a range, we construct a new string, which implies
>   copying the whole document.
>
> However, for the typical size of a C++ document and the frequency of
> update (at which a user types), it may not be an issue.  This patch aims
> at getting the basic feature in, and we can always improve it later if
> we find it's too slow.
>
> Signed-off-by: Simon Marchi 
>
> Reviewers: malaperle, ilya-biryukov
>
> Reviewed By: ilya-biryukov
>
> Subscribers: MaskRay, klimek, mgorny, ilya-biryukov, jkorous-apple,
> ioeric, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D44272
>
> Added:
> clang-tools-extra/trunk/test/clangd/textdocument-didchange-fail.test
> clang-tools-extra/trunk/unittests/clangd/DraftStoreTests.cpp
> Modified:
> clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
> clang-tools-extra/trunk/clangd/DraftStore.cpp
> clang-tools-extra/trunk/clangd/DraftStore.h
> clang-tools-extra/trunk/clangd/Protocol.cpp
> clang-tools-extra/trunk/clangd/Protocol.h
> clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
> clang-tools-extra/trunk/test/clangd/initialize-params.test
> clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
>
> Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=328500=328499=328500=diff
>
> ==
> --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
> +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Mar 26 07:41:40
> 2018
> @@ -100,7 +100,7 @@ void ClangdLSPServer::onInitialize(Initi
>reply(json::obj{
>{{"capabilities",
>  json::obj{
> -{"textDocumentSync", 1},
> +{"textDocumentSync", (int)TextDocumentSyncKind::Incremental},
>  {"documentFormattingProvider", true},
>  {"documentRangeFormattingProvider", true},
>  {"documentOnTypeFormattingProvider",
> @@ -147,25 +147,30 @@ void ClangdLSPServer::onDocumentDidOpen(
>PathRef File = Params.textDocument.uri.file();
>std::string  = Params.textDocument.text;
>
> -  DraftMgr.updateDraft(File, Contents);
> +  DraftMgr.addDraft(File, Contents);
>Server.addDocument(File, Contents, WantDiagnostics::Yes);
>  }
>
>  void ClangdLSPServer::onDocumentDidChange(DidChangeTextDocumentParams
> ) {
> -  if (Params.contentChanges.size() != 1)
> -return replyError(ErrorCode::InvalidParams,
> -  "can only apply one change at a time");
>auto WantDiags = WantDiagnostics::Auto;
>if (Params.wantDiagnostics.hasValue())
>  WantDiags = Params.wantDiagnostics.getValue() ? WantDiagnostics::Yes
>: WantDiagnostics::No;
>
>PathRef File = Params.textDocument.uri.file();
> -  std::string  = Params.contentChanges[0].text;
> +  llvm::Expected Contents =
> +  DraftMgr.updateDraft(File, Params.contentChanges);
> +  if (!Contents) {
> +// If this fails, we are most likely going to be not in sync anymore
> with
> +// the client.  It is better to remove the draft and let further
> operations
> +// fail rather than giving wrong results.
> +DraftMgr.removeDraft(File);
> +Server.removeDocument(File);
> +log(llvm::toString(Contents.takeError()));
> +return;
> +  }
>
> -  // We only support 

[clang-tools-extra] r328645 - Attempt to fix clangd test on Windows by wildcarding drive letters

2018-03-27 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Mar 27 10:44:12 2018
New Revision: 328645

URL: http://llvm.org/viewvc/llvm-project?rev=328645=rev
Log:
Attempt to fix clangd test on Windows by wildcarding drive letters

Modified:
clang-tools-extra/trunk/test/clangd/textdocument-didchange-fail.test

Modified: clang-tools-extra/trunk/test/clangd/textdocument-didchange-fail.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/textdocument-didchange-fail.test?rev=328645=328644=328645=diff
==
--- clang-tools-extra/trunk/test/clangd/textdocument-didchange-fail.test 
(original)
+++ clang-tools-extra/trunk/test/clangd/textdocument-didchange-fail.test Tue 
Mar 27 10:44:12 2018
@@ -19,7 +19,7 @@
 # CHECK-NEXT:  "line": 0
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
-# CHECK-NEXT:  "uri": "file:///clangd-test/main.cpp"
+# CHECK-NEXT:  "uri": "file://{{.*}}/clangd-test/main.cpp"
 # CHECK-NEXT:}
 # CHECK-NEXT:  ]
 ---


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


[PATCH] D33844: [clang-tidy] terminating continue check

2018-03-27 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: test/clang-tidy/misc-terminating-continue.cpp:7
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: terminating 'continue' 
[misc-terminating-continue]
+  } while(false);
+

Quuxplusone wrote:
> I initially expected to see tests also for
> 
> goto L1;
> while (false) {
> L1:
> continue;  // 'continue' is equivalent to 'break'
> }
> 
> int v = 0;
> goto L1;
> for (; false; ++v) {
> L1:
> continue;  // 'continue' is NOT equivalent to 'break'
> }
> 
> although I assume your current patch doesn't actually diagnose the former, 
> and that's probably fine.
I think both of your examples are out of scope for this check and are they 
realistic?

The usage of `goto` is addressed in `cppcoreguidelines-avoid-goto`


https://reviews.llvm.org/D33844



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


[PATCH] D44727: [RISCV] Implement getTargetDefines, handleTargetFeatures and hasFeature for RISCVTargetInfo

2018-03-27 Thread Ana Pazos via Phabricator via cfe-commits
apazos added inline comments.



Comment at: test/Preprocessor/riscv-target-features.c:9
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s 
-o - | FileCheck --check-prefix=CHECK-M-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64im -x c -E -dM %s 
-o - | FileCheck --check-prefix=CHECK-M-EXT %s

Consider breaking  the long lines to be within 80 cols.


Repository:
  rC Clang

https://reviews.llvm.org/D44727



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


[PATCH] D44815: [AArch64]: Add support for parsing rN registers.

2018-03-27 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

Thanks for the clarification. With that in mind I'm much less concerned that 
adding "r" as an alias will make extra warnings more difficult.  I agree that 
there should be at least a warning for register long x asm ("wn") although that 
is separate from this patch. Has anyone else got any objections?


Repository:
  rC Clang

https://reviews.llvm.org/D44815



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


[PATCH] D44189: [RISCV] Verify the input value of -march=

2018-03-27 Thread Ana Pazos via Phabricator via cfe-commits
apazos added inline comments.



Comment at: lib/Driver/ToolChains/Arch/RISCV.cpp:51
+  break;
+case 'g':
+  // g = imafd

One more question - how about non-standard extensions (vendor/custom) prefixed 
with X?
Shouldn't we add the logic to process 'Xext' occurrences in the march string as 
part of this patch?



Repository:
  rC Clang

https://reviews.llvm.org/D44189



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


[PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-03-27 Thread Yunlian Jiang via Phabricator via cfe-commits
yunlian updated this revision to Diff 139956.

https://reviews.llvm.org/D44788

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/lto-dwo.c


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -415,6 +415,16 @@
   if (IsThinLTO)
 CmdArgs.push_back("-plugin-opt=thinlto");
 
+  if (Arg *A = Args.getLastArg(options::OPT_glto_dwo_dir_EQ)) {
+const char *Objcopy =
+Args.MakeArgString(ToolChain.GetProgramPath(CLANG_DEFAULT_OBJCOPY));
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=objcopy=") + Objcopy));
+StringRef DWO_Dir = A->getValue();
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=dwo_dir=") + DWO_Dir));
+  }
+
   if (unsigned Parallelism = getLTOParallelism(Args, D))
 CmdArgs.push_back(
 Args.MakeArgString("-plugin-opt=jobs=" + Twine(Parallelism)));
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1700,6 +1700,7 @@
 def gcolumn_info : Flag<["-"], "gcolumn-info">, Group, 
Flags<[CoreOption]>;
 def gno_column_info : Flag<["-"], "gno-column-info">, Group, 
Flags<[CoreOption]>;
 def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group;
+def glto_dwo_dir_EQ : Joined<["-"], "glto-dwo-dir=">, Group;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, 
Flags<[CC1Option]>;
 def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group;
 def gmodules : Flag <["-"], "gmodules">, Group,
Index: docs/ClangCommandLineReference.rst
===
--- docs/ClangCommandLineReference.rst
+++ docs/ClangCommandLineReference.rst
@@ -2587,6 +2587,8 @@
 
 .. option:: -gstrict-dwarf, -gno-strict-dwarf
 
+.. option:: -glto-dwo-dir=
+
 .. option:: -gz
 
 DWARF debug sections compression type
Index: test/Driver/lto-dwo.c
===
--- /dev/null
+++ test/Driver/lto-dwo.c
@@ -0,0 +1,8 @@
+// Confirm that -glto-dwo-dir=DIR is passed to linker
+
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin 
-glto-dwo-dir=DIR 2> %t
+// RUN: FileCheck -check-prefix=CHECK-LINK-DWO-DIR < %t %s
+// RUN: FileCheck -check-prefix=CHECK-LINK-OBJCOPY < %t %s
+//
+// CHECK-LINK-DWO-DIR: "-plugin-opt=dwo_dir=DIR"
+// CHECK-LINK-OBJCOPY: "-plugin-opt=objcopy={{.*}}objcopy"


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -415,6 +415,16 @@
   if (IsThinLTO)
 CmdArgs.push_back("-plugin-opt=thinlto");
 
+  if (Arg *A = Args.getLastArg(options::OPT_glto_dwo_dir_EQ)) {
+const char *Objcopy =
+Args.MakeArgString(ToolChain.GetProgramPath(CLANG_DEFAULT_OBJCOPY));
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=objcopy=") + Objcopy));
+StringRef DWO_Dir = A->getValue();
+CmdArgs.push_back(
+Args.MakeArgString(Twine("-plugin-opt=dwo_dir=") + DWO_Dir));
+  }
+
   if (unsigned Parallelism = getLTOParallelism(Args, D))
 CmdArgs.push_back(
 Args.MakeArgString("-plugin-opt=jobs=" + Twine(Parallelism)));
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1700,6 +1700,7 @@
 def gcolumn_info : Flag<["-"], "gcolumn-info">, Group, Flags<[CoreOption]>;
 def gno_column_info : Flag<["-"], "gno-column-info">, Group, Flags<[CoreOption]>;
 def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group;
+def glto_dwo_dir_EQ : Joined<["-"], "glto-dwo-dir=">, Group;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, Flags<[CC1Option]>;
 def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group;
 def gmodules : Flag <["-"], "gmodules">, Group,
Index: docs/ClangCommandLineReference.rst
===
--- docs/ClangCommandLineReference.rst
+++ docs/ClangCommandLineReference.rst
@@ -2587,6 +2587,8 @@
 
 .. option:: -gstrict-dwarf, -gno-strict-dwarf
 
+.. option:: -glto-dwo-dir=
+
 .. option:: -gz
 
 DWARF debug sections compression type
Index: test/Driver/lto-dwo.c
===
--- /dev/null
+++ test/Driver/lto-dwo.c
@@ -0,0 +1,8 @@
+// Confirm that -glto-dwo-dir=DIR is passed to linker
+
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -glto-dwo-dir=DIR 2> %t
+// RUN: FileCheck -check-prefix=CHECK-LINK-DWO-DIR < %t %s
+// RUN: FileCheck -check-prefix=CHECK-LINK-OBJCOPY < %t %s
+//
+// CHECK-LINK-DWO-DIR: "-plugin-opt=dwo_dir=DIR"
+// CHECK-LINK-OBJCOPY: 

r328641 - Update test after r328635 in LLVM

2018-03-27 Thread Krzysztof Parzyszek via cfe-commits
Author: kparzysz
Date: Tue Mar 27 10:17:39 2018
New Revision: 328641

URL: http://llvm.org/viewvc/llvm-project?rev=328641=rev
Log:
Update test after r328635 in LLVM

Modified:
cfe/trunk/test/CodeGen/alias.c

Modified: cfe/trunk/test/CodeGen/alias.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alias.c?rev=328641=328640=328641=diff
==
--- cfe/trunk/test/CodeGen/alias.c (original)
+++ cfe/trunk/test/CodeGen/alias.c Tue Mar 27 10:17:39 2018
@@ -23,20 +23,20 @@ const int wacom_usb_ids[] = {1, 1, 2, 3,
 extern const int __mod_usb_device_table __attribute__ 
((alias("wacom_usb_ids")));
 // CHECKBASIC-DAG: @__mod_usb_device_table = alias i32, getelementptr inbounds 
([8 x i32], [8 x i32]* @wacom_usb_ids, i32 0, i32 0)
 // CHECKASM-DAG: .globl __mod_usb_device_table
-// CHECKASM-DAG: __mod_usb_device_table = wacom_usb_ids
+// CHECKASM-DAG: .set __mod_usb_device_table, wacom_usb_ids
 // CHECKASM-NOT: .size __mod_usb_device_table
 
 extern int g1;
 extern int g1 __attribute((alias("g0")));
 // CHECKBASIC-DAG: @g1 = alias i32, i32* @g0
 // CHECKASM-DAG: .globl g1
-// CHECKASM-DAG: g1 = g0
+// CHECKASM-DAG: .set g1, g0
 // CHECKASM-NOT: .size g1
 
 extern __thread int __libc_errno __attribute__ ((alias ("TL_WITH_ALIAS")));
 // CHECKBASIC-DAG: @__libc_errno = thread_local alias i32, i32* @TL_WITH_ALIAS
 // CHECKASM-DAG: .globl __libc_errno
-// CHECKASM-DAG: __libc_errno = TL_WITH_ALIAS
+// CHECKASM-DAG: .set __libc_errno, TL_WITH_ALIAS
 // CHECKASM-NOT: .size __libc_errno
 
 void f0(void) { }


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


[PATCH] D37115: [coroutines] Do not attempt to typo-correct when coroutine is looking for required members

2018-03-27 Thread Brian Gesiak via Phabricator via cfe-commits
modocache accepted this revision.
modocache added a comment.
This revision is now accepted and ready to land.

Excellent, thanks!


https://reviews.llvm.org/D37115



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


[PATCH] D33844: [clang-tidy] terminating continue check

2018-03-27 Thread Daniel Kolozsvari via Phabricator via cfe-commits
koldaniel updated this revision to Diff 139953.

https://reviews.llvm.org/D33844

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/TerminatingContinueCheck.cpp
  clang-tidy/misc/TerminatingContinueCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-terminating-continue.rst
  test/clang-tidy/misc-terminating-continue.cpp

Index: test/clang-tidy/misc-terminating-continue.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-terminating-continue.cpp
@@ -0,0 +1,65 @@
+// RUN: %check_clang_tidy %s misc-terminating-continue %t
+
+void f() {
+  do {
+continue;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'continue' in loop with false condition is equivalent to 'break' [misc-terminating-continue]
+// CHECK-FIXES: break;
+  } while(false);
+
+  do {
+continue;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'continue' in loop with false condition is equivalent to 'break' [misc-terminating-continue]
+// CHECK-FIXES: break;
+  } while(0);
+
+  do {
+continue;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'continue' in loop with false condition is equivalent to 'break' [misc-terminating-continue]
+// CHECK-FIXES: break;
+  } while(nullptr);
+
+  do {
+continue;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'continue' in loop with false condition is equivalent to 'break' [misc-terminating-continue]
+// CHECK-FIXES: break;
+  } while(__null);
+
+
+  do {
+int x = 1;
+if (x > 0) continue;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'continue' in loop with false condition is equivalent to 'break' [misc-terminating-continue]
+// CHECK-FIXES: if (x > 0) break;
+  } while (false);
+}
+
+void g() {
+  do {
+do {
+  continue;
+  int x = 1;
+} while (1 == 1);
+  } while (false);
+
+  do {
+for (int i = 0; i < 1; ++i) {
+  continue;
+  int x = 1;
+}
+  } while (false);
+
+  do {
+while (true) {
+  continue;
+  int x = 1;
+}
+  } while (false);
+
+  int v[] = {1,2,3,34};
+  do {
+for (int n : v) {
+  if (n>2) continue;
+}
+  } while (false);
+}
Index: docs/clang-tidy/checks/misc-terminating-continue.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-terminating-continue.rst
@@ -0,0 +1,34 @@
+.. title:: clang-tidy - misc-terminating-continue
+
+misc-terminating-continue
+=
+
+Detects `do while` loops with a condition always evaluating to false that
+have a `continue` statement, as this `continue` terminates the loop
+effectively.
+
+.. code-block:: c++
+
+  Parser::TPResult Parser::TryParseProtocolQualifiers() {
+assert(Tok.is(tok::less) && "Expected '<' for qualifier list");
+ConsumeToken();
+do {
+  if (Tok.isNot(tok::identifier))
+return TPResult::Error;
+  ConsumeToken();
+
+  if (Tok.is(tok::comma)) {
+ConsumeToken();
+
+//Terminating continue
+continue;
+  }
+
+  if (Tok.is(tok::greater)) {
+ConsumeToken();
+return TPResult::Ambiguous;
+  }
+} while (false);
+
+return TPResult::Error;
+  }
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -149,6 +149,7 @@
misc-non-copyable-objects
misc-redundant-expression
misc-static-assert
+   misc-terminating-continue
misc-throw-by-value-catch-by-reference
misc-unconventional-assign-operator
misc-uniqueptr-reset-release
Index: clang-tidy/misc/TerminatingContinueCheck.h
===
--- /dev/null
+++ clang-tidy/misc/TerminatingContinueCheck.h
@@ -0,0 +1,36 @@
+//===--- TerminatingContinueCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_TERMINATING_CONTINUE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_TERMINATING_CONTINUE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// Checks if a 'continue' statement terminates the loop (i.e. the loop has
+///	a condition which always evaluates to false).
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/misc-terminating-continue.html
+class TerminatingContinueCheck : public ClangTidyCheck {
+public:
+  TerminatingContinueCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const 

[PATCH] D44559: [Sema] Wrong width of result of mul operation

2018-03-27 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D44559#1049049, @avt77 wrote:

> > If that operation overflows, so be it — we're not going to warn about the 
> > potential for overflow every time the user adds two ints, and by the same 
> > token, it doesn't make any sense to warn about every time the user adds two 
> > shorts just because the language made this otherwise-unimportant technical 
> > decision to do the arithmetic in a wider type.
>
> There is one comment only: this patch changes the 'mul' operation only and 
> initially the change was done for X86 only because it clearly says about 
> "doubling" of mul result width.


Yes, I understand that addition was not changed by the patch.  I do not think 
that using different logic for multiplication is appropriate just because 
multiplication produces bigger values.  It is reasonable to multiply two 8-bit 
numbers and store the result in an 8-bit variable without a warning because the 
net effect is just doing a "closed" multiplication on an 8-bit type, which is a 
reasonable operation to want to do.  GCC is too noisy here.

There is nothing x86-specific about the supposed problem here, and using 
target-specific logic was always clearly inappropriate.

> And another comment: currently we have warning here:
> 
>   int c = a * b;
>   T d1 = c; // expected-warning{{implicit conversion loses integer precision: 
> 'int' to 'char'}}
>
> 
> but we don't have it here:
> 
> T d2 = a * b; // when T is char
> 
> It's a potential problem from my point of view.

All of these warnings are single-line analyses, which is unlikely to change 
absent massive architectural improvements to clang.  It has nothing to do with 
there being a multiplication; we would give you that exact same warning if you 
wrote `int c = a;`.

In https://reviews.llvm.org/D44559#1049057, @lebedev.ri wrote:

> In https://reviews.llvm.org/D44559#1049049, @avt77 wrote:
>
> > ...
> >  But I don't mind to close the review - and the corresponding bug of course.
>
>
> I disagree with closing the bug.
>  It's a real issue that is not detected/diagnosed by anything in clang 
> (diagnostic, sanitizer).
>
> It seems we are in a deadlock here :)


I don't have any special authority here besides having designed and implemented 
the current diagnostic.  You are welcome to start a thread on cfe-dev to gather 
support for changing the design of -Wconversion to always warn about the 
potential for overflow in sub-int multiplication. I will argue against you 
there, like I have here, but if there's consensus that we should warn about 
this, I'll abide by the community's judgment.


https://reviews.llvm.org/D44559



___
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-03-27 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 139948.
lebedev.ri retitled this revision from "[Sema] Extend -Wself-assign with 
-Wself-assign-overloaded to warn on overloaded self-assignment (classes)" to 
"[Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded 
self-assignment (classes)".
lebedev.ri edited the summary of this revision.
lebedev.ri added a comment.

- Dropped separate `-Wself-assign-builtin` and `-Wself-assign-overloaded` groups
- Simply updated the existing `-Wself-assign` and `-Wself-assign-field`.
- Significantly improved test coverage.
- `ninja check-clang` passes. Did not do stage2 build yet.
- `-Wself-assign-field` is rather neglected - unlike `-Wself-assign`, it does 
incorrectly warn on self-operations with `volatile` stores, and macros.


Repository:
  rC Clang

https://reviews.llvm.org/D44883

Files:
  docs/ReleaseNotes.rst
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/implicit-exception-spec.cpp
  test/SemaCXX/member-init.cpp
  test/SemaCXX/warn-self-assign-builtin.cpp
  test/SemaCXX/warn-self-assign-field-builtin.cpp
  test/SemaCXX/warn-self-assign-field-overloaded.cpp
  test/SemaCXX/warn-self-assign-overloaded.cpp
  test/SemaCXX/warn-self-assign.cpp

Index: test/SemaCXX/warn-self-assign-overloaded.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-self-assign-overloaded.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DDUMMY -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV0 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV1 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV3 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV4 -verify %s
+
+#ifdef DUMMY
+struct S {};
+#else
+struct S {
+#if defined(V0)
+  S() = default;
+#elif defined(V1)
+  S =(const S &) = default;
+#elif defined(V2)
+  S =(S &) = default;
+#elif defined(V3)
+  S =(const S &);
+#elif defined(V4)
+  S =(S &);
+#else
+#error Define something!
+#endif
+  S *=(const S &);
+  S /=(const S &);
+  S %=(const S &);
+  S +=(const S &);
+  S =(const S &);
+  S <<=(const S &);
+  S >>=(const S &);
+  S &=(const S &);
+  S |=(const S &);
+  S ^=(const S &);
+  S =(const volatile S &) volatile;
+};
+#endif
+
+void f() {
+  S a, b;
+  a = a; // expected-warning{{explicitly assigning}}
+  b = b; // expected-warning{{explicitly assigning}}
+  a = b;
+  b = a = b;
+  a = a = a; // expected-warning{{explicitly assigning}}
+  a = b = b = a;
+
+#ifndef DUMMY
+  a *= a;
+  a /= a; // expected-warning {{explicitly assigning}}
+  a %= a;
+  a += a;
+  a -= a; // expected-warning {{explicitly assigning}}
+  a <<= a;
+  a >>= a;
+  a &= a; // expected-warning {{explicitly assigning}}
+  a |= a; // expected-warning {{explicitly assigning}}
+  a ^= a; // expected-warning {{explicitly assigning}}
+#endif
+}
+
+void false_positives() {
+#define OP =
+#define LHS a
+#define RHS a
+  S a;
+  // These shouldn't warn due to the use of the preprocessor.
+  a OP a;
+  LHS = a;
+  a = RHS;
+  LHS OP RHS;
+#undef OP
+#undef LHS
+#undef RHS
+
+#ifndef DUMMY
+  // Volatile stores aren't side-effect free.
+  volatile S vol_a;
+  vol_a = vol_a;
+  volatile S _a_ref = vol_a;
+  vol_a_ref = vol_a_ref;
+#endif
+}
+
+template 
+void g() {
+  T a;
+  a = a; // expected-warning{{explicitly assigning}}
+}
+void instantiate() {
+  g();
+  g();
+}
Index: test/SemaCXX/warn-self-assign-field-overloaded.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-self-assign-field-overloaded.cpp
@@ -0,0 +1,142 @@
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DDUMMY -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV0 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV1 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV3 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV4 -verify %s
+
+#ifdef DUMMY
+struct S {};
+#else
+struct S {
+#if defined(V0)
+  S() = default;
+#elif defined(V1)
+  S =(const S &) = default;
+#elif defined(V2)
+  S =(S &) = default;
+#elif defined(V3)
+  S =(const S &);
+#elif defined(V4)
+  S =(S &);
+#else
+#error Define something!
+#endif
+  S *=(const S &);
+  S /=(const S &);
+  S %=(const S &);
+  S +=(const S &);
+  S =(const S &);
+  S <<=(const S &);
+  S >>=(const S &);
+  S &=(const S &);
+  S |=(const S &);
+  S ^=(const S &);
+  S =(const volatile S &) volatile;
+};
+#endif
+struct C {
+  S a;
+  S b;
+
+  void f() {
+a = a; // expected-warning {{assigning field to itself}}
+b = b; // expected-warning {{assigning field to itself}}
+a = b;
+
+this->a = a;   // expected-warning {{assigning field to itself}}
+this->b = b;   // expected-warning {{assigning field to itself}}
+a = this->a;   // expected-warning 

r328636 - [clang] Change std::sort to llvm::sort in response to r327219

2018-03-27 Thread Mandeep Singh Grang via cfe-commits
Author: mgrang
Date: Tue Mar 27 09:50:00 2018
New Revision: 328636

URL: http://llvm.org/viewvc/llvm-project?rev=328636=rev
Log:
[clang] Change std::sort to llvm::sort in response to r327219

r327219 added wrappers to std::sort which randomly shuffle the container before
sorting.  This will help in uncovering non-determinism caused due to undefined
sorting order of objects having the same key.

To make use of that infrastructure we need to invoke llvm::sort instead of
std::sort.

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/VTableBuilder.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
cfe/trunk/lib/Analysis/LiveVariables.cpp
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp
cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp
cfe/trunk/lib/Tooling/Core/Replacement.cpp
cfe/trunk/tools/diagtool/DiagTool.cpp
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp
cfe/trunk/utils/TableGen/ClangOptionDocEmitter.cpp
cfe/trunk/utils/TableGen/NeonEmitter.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=328636=328635=328636=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Mar 27 09:50:00 2018
@@ -1889,7 +1889,7 @@ def Target : InheritableAttr {
 template
 ParsedTargetAttr parse(Compare cmp) const {
   ParsedTargetAttr Attrs = parse();
-  std::sort(std::begin(Attrs.Features), std::end(Attrs.Features), cmp);
+  llvm::sort(std::begin(Attrs.Features), std::end(Attrs.Features), cmp);
   return Attrs;
 }
 

Modified: cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h?rev=328636=328635=328636=diff
==
--- cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h (original)
+++ cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h Tue Mar 27 
09:50:00 2018
@@ -117,7 +117,7 @@ public:
 Builder =(const Builder&) = delete;
 
 ~Builder() {
-  std::sort(Self.Rep.begin(), Self.Rep.end(), Compare());
+  llvm::sort(Self.Rep.begin(), Self.Rep.end(), Compare());
   std::unique(Self.Rep.begin(), Self.Rep.end(),
   [](const_reference A, const_reference B) {
 // FIXME: we should not allow any duplicate keys, but there are a lot 
of

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=328636=328635=328636=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Mar 27 09:50:00 2018
@@ -2186,7 +2186,7 @@ structHasUniqueObjectRepresentations(con
   }
 }
 
-std::sort(
+llvm::sort(
 Bases.begin(), Bases.end(), [&](const std::pair ,
 const std::pair ) 
{
   return Layout.getBaseClassOffset(L.first->getAsCXXRecordDecl()) <

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=328636=328635=328636=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Tue Mar 27 09:50:00 2018
@@ -323,7 +323,7 @@ class CXXNameMangler {
AdditionalAbiTags->end());
   }
 
-  std::sort(TagList.begin(), TagList.end());
+  llvm::sort(TagList.begin(), 

[PATCH] D44908: [ObjC++] Make parameter passing and function return compatible with ObjC

2018-03-27 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rC Clang

https://reviews.llvm.org/D44908



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


[PATCH] D44826: Add -Wunused-using, a warning that finds unused using declarations.

2018-03-27 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

You mention a missed case in the description - where the target of a using decl 
is used and that causes the unused-using not to warn about the using decl? That 
seems like a big limitation. Does that mean the 'used' bit is being tracked in 
the wrong place, on the target of the using decl instead of on the using decl 
itself?




Comment at: lib/Sema/MultiplexExternalSemaSource.cpp:278-279
+llvm::SmallSetVector ) {
+  for(size_t i = 0; i < Sources.size(); ++i)
+Sources[i]->ReadUnusedUsingCandidates(Decls);
+}

Could you use a range-based-for here?



Comment at: lib/Serialization/ASTReader.cpp:8101-8103
+UsingDecl *D = dyn_cast_or_null(
+GetDecl(UnusedUsingCandidates[I]));
+if (D)

roll the declaration into the condition, perhaps:

  if (auto *D = dyn_cast_or_null...)
Decls.insert(D);



Comment at: test/Modules/warn-unused-using.cpp:5
+
+// For modules, the warning should only fire the first time, when the module is
+// built.

This would only warn for the unused local using, but wouldn't fire for an 
namespace-scoped unused using? Perhaps there should be a test for that?



Comment at: test/SemaCXX/warn-unused-using.cpp:6-8
+  typedef int INT;
+  typedef char CHAR;
+  typedef float FLOAT;

Do these need to be different types? Maybe just name them t1/t2/t3/t4, etc - or 
name them after their use in test cases to indicate what makes each type 
interesting/different, if that's suitable.



Comment at: test/SemaCXX/warn-unused-using.cpp:11-12
+
+using nsp::Print; // expected-warning {{unused using 'Print'}}
+using nsp::var; // expected-warning {{unused using 'var'}}
+

What's the difference between these two cases?



Comment at: test/SemaCXX/warn-unused-using.cpp:15-20
+  using nsp::Print; // expected-warning {{unused using 'Print'}}
+  {
+using nsp::var; // expected-warning {{unused using 'var'}}
+{
+  using nsp::INT; // expected-warning {{unused using 'INT'}}
+  using nsp::FLOAT; // expected-warning {{unused using 'FLOAT'}}

And these 4? (I guess one in a nested scope is significant in some way? But not 
sure about the second scope, and the two (rather than one) using decls in there)



Comment at: test/SemaCXX/warn-unused-using.cpp:28
+  FLOAT f;
+  f = 2.0;
+}

Probably don't need this use? (can turn off all the other warnings, rather than 
crafting warning-free code when testing only one warning)



Comment at: test/SemaCXX/warn-unused-using.cpp:35
+struct B : A {
+  using A::Foo;  // expected-warning {{unused using 'Foo'}}
+  virtual void Foo(double x) const;

This tests the fact that 'Foo' is overridden in B anyway, so this using decl 
doesn't bring anything in?

I'm assuming in the case where the using decl does bring at least one name in, 
this warning doesn't fire? (maybe test that?)



Comment at: test/SemaCXX/warn-unused-using.cpp:39-42
+void one() {
+  B b;
+  b.Foo(1.0);
+}

Does B need to be used at all, here? Oh, to demonstrate that 'Foo' is using one 
overload, but not using the using decl?


Repository:
  rC Clang

https://reviews.llvm.org/D44826



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


[PATCH] D44916: [Sema] Avoid crash for category implementation without interface

2018-03-27 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I think that's a fine place to add the check.


Repository:
  rC Clang

https://reviews.llvm.org/D44916



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


[PATCH] D35068: [analyzer] Detect usages of unsafe I/O functions

2018-03-27 Thread Daniel Kolozsvari via Phabricator via cfe-commits
koldaniel added a comment.

Do you have any other comments, or could this change be accepted?


https://reviews.llvm.org/D35068



___
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-03-27 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis added inline comments.



Comment at: clang-tidy/ClangTidy.cpp:490
+CommandLineArguments AdjustedArgs = Args;
+AdjustedArgs.emplace_back("-D__clang_analyzer__");
+return AdjustedArgs;

alexfh wrote:
> I wonder whether we should instead reuse the logic in the frontend 
> (tools/clang/lib/Frontend/InitPreprocessor.cpp:970). This could be done by 
> overriding ActionFactory::runInvocation and setting 
> FrontendOptions::ProgramAction to frontend::RunAnalysis there. WDYT?
Thanks. I know about this code. But I'm not sure that we can reuse RunAnalysys 
action hre - we need to parse AST only, but RunAnalysys does a lot of other 
things we dont' need. Is it correct?


Repository:
  rCTE Clang Tools Extra

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-03-27 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/ClangTidy.cpp:490
+CommandLineArguments AdjustedArgs = Args;
+AdjustedArgs.emplace_back("-D__clang_analyzer__");
+return AdjustedArgs;

I wonder whether we should instead reuse the logic in the frontend 
(tools/clang/lib/Frontend/InitPreprocessor.cpp:970). This could be done by 
overriding ActionFactory::runInvocation and setting 
FrontendOptions::ProgramAction to frontend::RunAnalysis there. WDYT?


Repository:
  rCTE Clang Tools Extra

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] D44908: [ObjC++] Make parameter passing and function return compatible with ObjC

2018-03-27 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 139935.
ahatanak added a comment.

Make ClangABICompat a LangOption and remove ForcePassIndirectly. Move the logic 
in CodeGen that decides whether a parameter should be passed indirectly to Sema.


Repository:
  rC Clang

https://reviews.llvm.org/D44908

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Basic/TargetInfo.h
  include/clang/Frontend/CodeGenOptions.def
  lib/AST/ASTContext.cpp
  lib/AST/Decl.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
  test/CodeGenObjCXX/arc-special-member-functions.mm
  test/CodeGenObjCXX/objc-struct-cxx-abi.mm
  test/CodeGenObjCXX/property-dot-copy-elision.mm
  test/CodeGenObjCXX/trivial_abi.mm

Index: test/CodeGenObjCXX/property-dot-copy-elision.mm
===
--- test/CodeGenObjCXX/property-dot-copy-elision.mm
+++ test/CodeGenObjCXX/property-dot-copy-elision.mm
@@ -1,11 +1,13 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -std=c++1z -fobjc-arc -o - %s | FileCheck %s
 
 struct S0 {
+  ~S0();
   id f;
 };
 
 struct S1 {
   S1();
+  ~S1();
   S1(S0);
   id f;
 };
Index: test/CodeGenObjCXX/objc-struct-cxx-abi.mm
===
--- test/CodeGenObjCXX/objc-struct-cxx-abi.mm
+++ test/CodeGenObjCXX/objc-struct-cxx-abi.mm
@@ -1,27 +1,60 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fobjc-arc  -fobjc-weak -fobjc-runtime-has-weak -emit-llvm -o - %s | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fobjc-arc  -fobjc-weak -fobjc-runtime-has-weak -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fobjc-arc  -fobjc-weak -fobjc-runtime-has-weak -emit-llvm -o - -DTRIVIALABI %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fobjc-arc  -fobjc-weak -fobjc-runtime-has-weak -fclang-abi-compat=4.0 -emit-llvm -o - -DTRIVIALABI %s | FileCheck %s
+
+// Check that structs consisting solely of __strong or __weak pointer fields are
+// destructed in the callee function and structs consisting solely of __strong
+// pointer fields are passed directly.
 
 // CHECK: %[[STRUCT_STRONGWEAK:.*]] = type { i8*, i8* }
 // CHECK: %[[STRUCT_STRONG:.*]] = type { i8* }
 // CHECK: %[[STRUCT_S:.*]] = type { i8* }
+// CHECK: %[[STRUCT_CONTAINSNONTRIVIAL:.*]] = type { %{{.*}}, i8* }
 
+#ifdef TRIVIALABI
 struct __attribute__((trivial_abi)) StrongWeak {
+#else
+struct StrongWeak {
+#endif
   id fstrong;
   __weak id fweak;
 };
 
+#ifdef TRIVIALABI
 struct __attribute__((trivial_abi)) Strong {
+#else
+struct Strong {
+#endif
   id fstrong;
 };
 
 template
+#ifdef TRIVIALABI
 struct __attribute__((trivial_abi)) S {
+#else
+struct S {
+#endif
   T a;
 };
 
+struct NonTrivial {
+  NonTrivial();
+  NonTrivial(const NonTrivial &);
+  ~NonTrivial();
+  int *a;
+};
+
+// This struct is not passed directly nor destructed in the callee because f0
+// has type NonTrivial.
+struct ContainsNonTrivial {
+  NonTrivial f0;
+  id f1;
+};
+
 // CHECK: define void @_Z19testParamStrongWeak10StrongWeak(%[[STRUCT_STRONGWEAK]]* %{{.*}})
-// CHECK-NOT: call
-// CHECK: ret void
+// CHECK: call %struct.StrongWeak* @_ZN10StrongWeakD1Ev(
+// CHECK-NEXT: ret void
 
 void testParamStrongWeak(StrongWeak a) {
 }
@@ -33,7 +66,7 @@
 // CHECK: %[[V0:.*]] = load %[[STRUCT_STRONGWEAK]]*, %[[STRUCT_STRONGWEAK]]** %[[A_ADDR]], align 8
 // CHECK: %[[CALL:.*]] = call %[[STRUCT_STRONGWEAK]]* @_ZN10StrongWeakC1ERKS_(%[[STRUCT_STRONGWEAK]]* %[[AGG_TMP]], %[[STRUCT_STRONGWEAK]]* dereferenceable(16) %[[V0]])
 // CHECK: call void @_Z19testParamStrongWeak10StrongWeak(%[[STRUCT_STRONGWEAK]]* %[[AGG_TMP]])
-// CHECK: %[[CALL1:.*]] = call %[[STRUCT_STRONGWEAK]]* @_ZN10StrongWeakD1Ev(%[[STRUCT_STRONGWEAK]]* %[[AGG_TMP]])
+// CHECK-NOT: call
 // CHECK: ret void
 
 void testCallStrongWeak(StrongWeak *a) {
@@ -96,8 +129,23 @@
 }
 
 // CHECK: define void @_Z21testParamWeakTemplate1SIU6__weakP11objc_objectE(%[[STRUCT_S]]* %{{.*}})
+// CHECK: call %struct.S* @_ZN1SIU6__weakP11objc_objectED1Ev(
+// CHECK-NEXT: ret void
+
+void testParamWeakTemplate(S<__weak id> a) {
+}
+
+// CHECK: define void @_Z27testParamContainsNonTrivial18ContainsNonTrivial(%[[STRUCT_CONTAINSNONTRIVIAL]]* %{{.*}})
 // CHECK-NOT: call
 // CHECK: ret void
 
-void testParamWeakTemplate(S<__weak id> a) {
+void testParamContainsNonTrivial(ContainsNonTrivial a) {
+}
+
+// CHECK: 

[PATCH] D44831: [clang-format] Refine ObjC guesser to handle child lines of child lines

2018-03-27 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328628: [clang-format] Refine ObjC guesser to handle child 
lines of child lines (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44831?vs=139929=139932#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44831

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12159,6 +12159,12 @@
 guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
 guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ std::string s; }) })"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ NSString *s; }) })"));
 }
 
 } // end namespace
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@
 "UIView",
 };
 
-auto LineContainsObjCCode = [](const AnnotatedLine ) {
-  for (const FormatToken *FormatTok = Line.First; FormatTok;
+for (auto Line : AnnotatedLines) {
+  for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1535,14 +1535,7 @@
TT_ObjCMethodSpecifier, TT_ObjCProperty)) {
   return true;
 }
-  }
-  return false;
-};
-for (auto Line : AnnotatedLines) {
-  if (LineContainsObjCCode(*Line))
-return true;
-  for (auto ChildLine : Line->Children) {
-if (LineContainsObjCCode(*ChildLine))
+if (guessIsObjC(Line->Children, Keywords))
   return true;
   }
 }


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12159,6 +12159,12 @@
 guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
 guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ std::string s; }) })"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ NSString *s; }) })"));
 }
 
 } // end namespace
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@
 "UIView",
 };
 
-auto LineContainsObjCCode = [](const AnnotatedLine ) {
-  for (const FormatToken *FormatTok = Line.First; FormatTok;
+for (auto Line : AnnotatedLines) {
+  for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1535,14 +1535,7 @@
TT_ObjCMethodSpecifier, TT_ObjCProperty)) {
   return true;
 }
-  }
-  return false;
-};
-for (auto Line : AnnotatedLines) {
-  if (LineContainsObjCCode(*Line))
-return true;
-  for (auto ChildLine : Line->Children) {
-if (LineContainsObjCCode(*ChildLine))
+if (guessIsObjC(Line->Children, Keywords))
   return true;
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44816: [clang-format] Do not insert space before closing brace in ObjC dict literal

2018-03-27 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328627: [clang-format] Do not insert space before closing 
brace in ObjC dict literal (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44816?vs=139930=139931#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44816

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


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2480,6 +2480,10 @@
 return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
 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.
+return false;
   return true;
 }
 
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1000,6 +1000,21 @@
   "  ( id)a : ( id),\n"
   "  ( id)aa : ( id)aa,\n"
   "};");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{a12345 : a12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{b12345: b12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{(Foo *)b12345: @(b12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   verifyFormat(
@@ -1055,6 +1070,21 @@
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @[ a12345, a12345 ];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a123 = @[ (Foo *)a12345, @(a12345) ];\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[b12345, b12345];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[(Foo *)b12345, @(b12345)];\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
   Style.ColumnLimit = 20;
   // We can't break string literals inside NSArray literals
   // (that raises -Wobjc-string-concatenation).


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2480,6 +2480,10 @@
 return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
 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.
+return false;
   return true;
 }
 
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1000,6 +1000,21 @@
   "  ( id)a : ( id),\n"
   "  ( id)aa : ( id)aa,\n"
   "};");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{a12345 : a12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{b12345: b12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{(Foo *)b12345: @(b12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   verifyFormat(
@@ -1055,6 +1070,21 @@
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @[ a12345, a12345 ];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a123 = @[ (Foo *)a12345, @(a12345) ];\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[b12345, b12345];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 

[PATCH] D44816: [clang-format] Do not insert space before closing brace in ObjC dict literal

2018-03-27 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

I filed https://bugs.llvm.org/show_bug.cgi?id=36919 to follow up and make ObjC 
dictionary literal spacing consistent with ObjC array literals.


Repository:
  rC Clang

https://reviews.llvm.org/D44816



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


r328627 - [clang-format] Do not insert space before closing brace in ObjC dict literal

2018-03-27 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Tue Mar 27 08:01:17 2018
New Revision: 328627

URL: http://llvm.org/viewvc/llvm-project?rev=328627=rev
Log:
[clang-format] Do not insert space before closing brace in ObjC dict literal

Summary:
Previously, `clang-format` would sometimes insert a space
before the closing brace in an Objective-C dictionary literal.

Unlike array literals (which obey `Style.SpacesInContainerLiterals`
to add a space after `[` and before `]`), Objective-C dictionary
literals currently are not meant to insert a space after `{` and before
`}`, regardless of `Style.SpacesInContainerLiterals`.

However, some constructs like `@{foo : @(bar)}` caused `clang-format`
to insert a space between `)` and `}`.

This fixes the issue and adds tests. (I understand the behavior is
not consistent between array literals and dictionary literals, but
that's existing behavior that's a much larger change.)

Test Plan: New tests added. Ran tests with:
  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: djasper, jolesiak, Wizard

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=328627=328626=328627=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Mar 27 08:01:17 2018
@@ -2480,6 +2480,10 @@ bool TokenAnnotator::spaceRequiredBetwee
 return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
 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.
+return false;
   return true;
 }
 

Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=328627=328626=328627=diff
==
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Tue Mar 27 08:01:17 2018
@@ -1000,6 +1000,21 @@ TEST_F(FormatTestObjC, ObjCDictLiterals)
   "  ( id)a : ( id),\n"
   "  ( id)aa : ( id)aa,\n"
   "};");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{a12345 : a12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{b12345: b12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{(Foo *)b12345: @(b12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   verifyFormat(
@@ -1055,6 +1070,21 @@ TEST_F(FormatTestObjC, ObjCArrayLiterals
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @[ a12345, a12345 ];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a123 = @[ (Foo *)a12345, @(a12345) ];\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[b12345, b12345];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[(Foo *)b12345, @(b12345)];\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
   Style.ColumnLimit = 20;
   // We can't break string literals inside NSArray literals
   // (that raises -Wobjc-string-concatenation).


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


r328628 - [clang-format] Refine ObjC guesser to handle child lines of child lines

2018-03-27 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Tue Mar 27 08:01:21 2018
New Revision: 328628

URL: http://llvm.org/viewvc/llvm-project?rev=328628=rev
Log:
[clang-format] Refine ObjC guesser to handle child lines of child lines

Summary:
This fixes an issue brought up by djasper@ in his review of D44790. We
handled top-level child lines, but if those child lines themselves
had child lines, we didn't handle them.

Rather than use recursion (which could blow out the stack), I use a
DenseSet to hold the set of lines we haven't yet checked (since order
doesn't matter), and update the set to add the children of each
line as we check it.

Test Plan: New tests added. Confirmed tests failed before fix
  and passed after fix.

Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=328628=328627=328628=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Mar 27 08:01:21 2018
@@ -1514,8 +1514,8 @@ private:
 "UIView",
 };
 
-auto LineContainsObjCCode = [](const AnnotatedLine ) {
-  for (const FormatToken *FormatTok = Line.First; FormatTok;
+for (auto Line : AnnotatedLines) {
+  for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1535,14 +1535,7 @@ private:
TT_ObjCMethodSpecifier, TT_ObjCProperty)) {
   return true;
 }
-  }
-  return false;
-};
-for (auto Line : AnnotatedLines) {
-  if (LineContainsObjCCode(*Line))
-return true;
-  for (auto ChildLine : Line->Children) {
-if (LineContainsObjCCode(*ChildLine))
+if (guessIsObjC(Line->Children, Keywords))
   return true;
   }
 }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=328628=328627=328628=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Mar 27 08:01:21 2018
@@ -12159,6 +12159,12 @@ TEST_F(FormatTest, GuessLanguageWithChil
 guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
 guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ std::string s; }) })"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ NSString *s; }) })"));
 }
 
 } // end namespace


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


r328626 - Drop spurious break; NFC

2018-03-27 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Tue Mar 27 07:57:56 2018
New Revision: 328626

URL: http://llvm.org/viewvc/llvm-project?rev=328626=rev
Log:
Drop spurious break; NFC

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=328626=328625=328626=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Mar 27 07:57:56 2018
@@ -1209,7 +1209,6 @@ Sema::CheckBuiltinFunctionCall(FunctionD
 if (SemaOpenCLBuiltinKernelWorkGroupSize(*this, TheCall))
   return ExprError();
 break;
-break;
   case Builtin::BIget_kernel_max_sub_group_size_for_ndrange:
   case Builtin::BIget_kernel_sub_group_count_for_ndrange:
 if (SemaOpenCLBuiltinNDRangeAndBlock(*this, TheCall))


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


[PATCH] D44816: [clang-format] Do not insert space before closing brace in ObjC dict literal

2018-03-27 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.

Yeah, it's one of these things where neither way would be totally intuitive to 
everyone.


Repository:
  rC Clang

https://reviews.llvm.org/D44816



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


[PATCH] D44831: [clang-format] Refine ObjC guesser to handle child lines of child lines

2018-03-27 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/D44831



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


[PATCH] D44816: [clang-format] Do not insert space before closing brace in ObjC dict literal

2018-03-27 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:2484
+  if (Right.is(tok::r_brace) && Right.MatchingParen &&
+  Right.MatchingParen->is(TT_DictLiteral) &&
+  Right.MatchingParen->Previous &&

djasper wrote:
> Could you use Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at) here?
Yes, done. I keep forgetting about the reverse order of that method (it makes 
sense, I just can't keep that info in my brain for some reason.)


Repository:
  rC Clang

https://reviews.llvm.org/D44816



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


[PATCH] D44816: [clang-format] Do not insert space before closing brace in ObjC dict literal

2018-03-27 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 139930.
benhamilton marked an inline comment as done.
benhamilton added a comment.

- Use `Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at)`


Repository:
  rC Clang

https://reviews.llvm.org/D44816

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


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1000,6 +1000,21 @@
   "  ( id)a : ( id),\n"
   "  ( id)aa : ( id)aa,\n"
   "};");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{a12345 : a12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{b12345: b12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{(Foo *)b12345: @(b12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   verifyFormat(
@@ -1055,6 +1070,21 @@
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @[ a12345, a12345 ];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a123 = @[ (Foo *)a12345, @(a12345) ];\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[b12345, b12345];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[(Foo *)b12345, @(b12345)];\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
   Style.ColumnLimit = 20;
   // We can't break string literals inside NSArray literals
   // (that raises -Wobjc-string-concatenation).
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2480,6 +2480,10 @@
 return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
 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.
+return false;
   return true;
 }
 


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1000,6 +1000,21 @@
   "  ( id)a : ( id),\n"
   "  ( id)aa : ( id)aa,\n"
   "};");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{a12345 : a12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{b12345: b12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @{(Foo *)b12345: @(b12345)};\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   verifyFormat(
@@ -1055,6 +1070,21 @@
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 40;
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @[ a12345, a12345 ];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a123 = @[ (Foo *)a12345, @(a12345) ];\n"
+   "}");
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[b12345, b12345];\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  b12345 = @[(Foo *)b12345, @(b12345)];\n"
+   "}");
+  Style.SpacesInContainerLiterals = true;
   Style.ColumnLimit = 20;
   // We can't break string literals inside NSArray literals
   // (that raises -Wobjc-string-concatenation).
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2480,6 +2480,10 @@
 return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
 return false;
+  if (Right.is(tok::r_brace) && Right.MatchingParen &&
+  

[PATCH] D44831: [clang-format] Refine ObjC guesser to handle child lines of child lines

2018-03-27 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added inline comments.



Comment at: lib/Format/Format.cpp:1449
   const AdditionalKeywords ) {
+for (auto Line : AnnotatedLines)
+  if (LineContainsObjCCode(*Line, Keywords))

djasper wrote:
> I would not create a second function here. Just iterate over the tokens here 
> and call guessIsObjC recursively with Line->Children. That means we need one 
> less for loop overall, I think (I might be missing something).
Good call, done.

I don't know why I didn't do that first! For some reason, my brain thought 
`Line.Children` was an incompatible type..



Comment at: lib/Format/Format.cpp:1455
+
+  static bool LineContainsObjCCode(const AnnotatedLine ,
+   const AdditionalKeywords ) {

djasper wrote:
> Convention would be lineContainsObjCCode.
Removed.


Repository:
  rC Clang

https://reviews.llvm.org/D44831



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


[PATCH] D44831: [clang-format] Refine ObjC guesser to handle child lines of child lines

2018-03-27 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 139929.
benhamilton marked 2 inline comments as done.
benhamilton added a comment.

- Simplify recursion. Remove static method LineContainsObjCCode().


Repository:
  rC Clang

https://reviews.llvm.org/D44831

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12171,6 +12171,12 @@
 guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
 guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ std::string s; }) })"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ NSString *s; }) })"));
 }
 
 } // end namespace
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@
 "UIView",
 };
 
-auto LineContainsObjCCode = [](const AnnotatedLine ) {
-  for (const FormatToken *FormatTok = Line.First; FormatTok;
+for (auto Line : AnnotatedLines) {
+  for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1535,14 +1535,7 @@
TT_ObjCMethodSpecifier, TT_ObjCProperty)) {
   return true;
 }
-  }
-  return false;
-};
-for (auto Line : AnnotatedLines) {
-  if (LineContainsObjCCode(*Line))
-return true;
-  for (auto ChildLine : Line->Children) {
-if (LineContainsObjCCode(*ChildLine))
+if (guessIsObjC(Line->Children, Keywords))
   return true;
   }
 }


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12171,6 +12171,12 @@
 guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
 guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ std::string s; }) })"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "#define FOO ({ foo(); ({ NSString *s; }) })"));
 }
 
 } // end namespace
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@
 "UIView",
 };
 
-auto LineContainsObjCCode = [](const AnnotatedLine ) {
-  for (const FormatToken *FormatTok = Line.First; FormatTok;
+for (auto Line : AnnotatedLines) {
+  for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1535,14 +1535,7 @@
TT_ObjCMethodSpecifier, TT_ObjCProperty)) {
   return true;
 }
-  }
-  return false;
-};
-for (auto Line : AnnotatedLines) {
-  if (LineContainsObjCCode(*Line))
-return true;
-  for (auto ChildLine : Line->Children) {
-if (LineContainsObjCCode(*ChildLine))
+if (guessIsObjC(Line->Children, Keywords))
   return true;
   }
 }
___
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-03-27 Thread Henry Wong via Phabricator via cfe-commits
MTC created this revision.
MTC added reviewers: dcoughlin, NoQ, xazax.hun, a.sidorin.
Herald added subscribers: cfe-commits, rnkovacs, szepet.
Herald added a reviewer: george.karpenkov.

This patch originates from https://reviews.llvm.org/D31868. There are two key 
points in this 
patch:

- Add `OverwriteRegion()`, this method used to model `memset()` or something 
like that.
- Improve the modeling of `memset`.

For `OverwriteRegion()`, is basically invalidate region and bind default. But I 
think this 
method requires more in-depth thinking and more extensive testing.

For `evalMemset()`, this patch only considers the case where the buffer's 
offset is zero. And
if the whole region is `memset`ed, bind a default value. According to the value 
for 
overwriting, decide how to update the string length.

For `void *memset(void *dest, int ch, size_t count)`:

1). offset is 0, `ch` is `'\0'` and `count` < dest-buffer's length. 
Invalidate the buffer and set the string length to 0.

2). offset is 0, `ch` is `'\0'` and `count` == dest-buffer's length.
Bind `\0` to the buffer with default binding and set the string length to 0.

3). offset is 0, `ch` is not `'\0'` and `count` < dest-buffer's length.
Invalidate the buffer and set the string length >= `count`.

4). offset is 0, `ch` is not `'\0'` and `count` == dest-buffer's length.
Bind `ch` to the buffer and set the string length >= `count`.

I have tested this patch on `sqlite`, but there's no difference int the 
warnings.

Thanks in advance for the review!


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);
+  

[PATCH] D44480: [Sema] Don't skip function bodies with 'auto' without trailing return type

2018-03-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

I hit that bug in practice a few days ago when playing around with a C++17 
codebase. It makes completion totally unusable when functions with auto-deduced 
return type are used.
@rsmith, any chance you could take a look? Or maybe suggest someone else as a 
reviewer?


Repository:
  rC Clang

https://reviews.llvm.org/D44480



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


[PATCH] D44480: [Sema] Don't skip function bodies with 'auto' without trailing return type

2018-03-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 139926.
ilya-biryukov added a comment.

- Replace auto with explicit type


Repository:
  rC Clang

https://reviews.llvm.org/D44480

Files:
  lib/Sema/SemaDecl.cpp
  test/CodeCompletion/crash-skipped-bodies-template-inst.cpp


Index: test/CodeCompletion/crash-skipped-bodies-template-inst.cpp
===
--- /dev/null
+++ test/CodeCompletion/crash-skipped-bodies-template-inst.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:24:5 %s -o - 2>&1 | 
FileCheck %s
+template 
+auto make_func() {
+  struct impl {
+impl* func() {
+  int x;
+  if (x = 10) {}
+  // Check that body of this function is actually skipped.
+  // CHECK-NOT: crash-skipped-bodies-template-inst.cpp:7:{{[0-9]+}}: 
warning: using the result of an assignment as a condition without parentheses
+  return this;
+}
+  };
+
+  int x;
+  if (x = 10) {}
+  // Check that this function is not skipped.
+  // CHECK: crash-skipped-bodies-template-inst.cpp:15:9: warning: using the 
result of an assignment as a condition without parentheses
+  return impl();
+}
+
+void foo() {
+  []() {
+make_func();
+m
+// CHECK: COMPLETION: make_func : [#auto#]make_func<<#class T#>>()
+  };
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12603,9 +12603,15 @@
   // rest of the file.
   // We cannot skip the body of a function with an undeduced return type,
   // because any callers of that function need to know the type.
-  if (const FunctionDecl *FD = D->getAsFunction())
-if (FD->isConstexpr() || FD->getReturnType()->isUndeducedType())
+  if (const FunctionDecl *FD = D->getAsFunction()) {
+if (FD->isConstexpr())
   return false;
+// We can't simply call Type::isUndeducedType here, because it returns
+// false on C++14's auto return type without trailing return type.
+DeducedType *DT = FD->getReturnType()->getContainedDeducedType();
+if (DT && DT->getDeducedType().isNull())
+  return false;
+  }
   return Consumer.shouldSkipFunctionBody(D);
 }
 


Index: test/CodeCompletion/crash-skipped-bodies-template-inst.cpp
===
--- /dev/null
+++ test/CodeCompletion/crash-skipped-bodies-template-inst.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:24:5 %s -o - 2>&1 | FileCheck %s
+template 
+auto make_func() {
+  struct impl {
+impl* func() {
+  int x;
+  if (x = 10) {}
+  // Check that body of this function is actually skipped.
+  // CHECK-NOT: crash-skipped-bodies-template-inst.cpp:7:{{[0-9]+}}: warning: using the result of an assignment as a condition without parentheses
+  return this;
+}
+  };
+
+  int x;
+  if (x = 10) {}
+  // Check that this function is not skipped.
+  // CHECK: crash-skipped-bodies-template-inst.cpp:15:9: warning: using the result of an assignment as a condition without parentheses
+  return impl();
+}
+
+void foo() {
+  []() {
+make_func();
+m
+// CHECK: COMPLETION: make_func : [#auto#]make_func<<#class T#>>()
+  };
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12603,9 +12603,15 @@
   // rest of the file.
   // We cannot skip the body of a function with an undeduced return type,
   // because any callers of that function need to know the type.
-  if (const FunctionDecl *FD = D->getAsFunction())
-if (FD->isConstexpr() || FD->getReturnType()->isUndeducedType())
+  if (const FunctionDecl *FD = D->getAsFunction()) {
+if (FD->isConstexpr())
   return false;
+// We can't simply call Type::isUndeducedType here, because it returns
+// false on C++14's auto return type without trailing return type.
+DeducedType *DT = FD->getReturnType()->getContainedDeducedType();
+if (DT && DT->getDeducedType().isNull())
+  return false;
+  }
   return Consumer.shouldSkipFunctionBody(D);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44932: [CodeComplete] Fix completion in the middle of ident in ctor lists.

2018-03-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: sammccall, aaron.ballman, bkramer, sepavloff.

The example that was broken before (^ designate completion points):

  class Foo {
Foo() : fie^ld^() {} // no completions were provided here.
int field;
  };

To fix it we don't cut off lexing after an identifier followed by code
completion token is lexed. Instead we skip the rest of identifier and
continue lexing.
This is consistent with behavior of completion when completion token is
right before the identifier.


Repository:
  rC Clang

https://reviews.llvm.org/D44932

Files:
  lib/Lex/Lexer.cpp
  test/CodeCompletion/ctor-initializer.cpp


Index: test/CodeCompletion/ctor-initializer.cpp
===
--- test/CodeCompletion/ctor-initializer.cpp
+++ test/CodeCompletion/ctor-initializer.cpp
@@ -58,5 +58,9 @@
   // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s 
-o - | FileCheck -check-prefix=CHECK-CC7 %s
   // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s 
-o - | FileCheck -check-prefix=CHECK-CC7 %s
   // CHECK-CC7: COMPLETION: Pattern : member1(<#args#>
+  // Check in the middle and at the end of identifier too.
+  // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s 
-o - | FileCheck -check-prefix=CHECK-CC8 %s
+  // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s 
-o - | FileCheck -check-prefix=CHECK-CC8 %s
+  // CHECK-CC8: COMPLETION: Pattern : member2(<#args#>
   int member1, member2;
 };
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -1656,7 +1656,17 @@
 && II->getObjCKeywordID() == tok::objc_not_keyword) {
   // Return the code-completion token.
   Result.setKind(tok::code_completion);
-  cutOffLexing();
+  // Skip the code-completion char and all immediate identifier characters.
+  // This ensures we get consistent behavior when completing at any point 
in
+  // an identifier (i.e. at the start, in the middle, at the end). Note 
that
+  // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code
+  // simpler.
+  assert(*CurPtr == 0 && "Completion character must be 0");
+  ++CurPtr;
+  assert(CurPtr < BufferEnd && "eof at completion point");
+  while (isIdentifierBody(*CurPtr))
+++CurPtr;
+  BufferPtr = CurPtr;
   return true;
 }
 return true;


Index: test/CodeCompletion/ctor-initializer.cpp
===
--- test/CodeCompletion/ctor-initializer.cpp
+++ test/CodeCompletion/ctor-initializer.cpp
@@ -58,5 +58,9 @@
   // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
   // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
   // CHECK-CC7: COMPLETION: Pattern : member1(<#args#>
+  // Check in the middle and at the end of identifier too.
+  // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s
+  // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s
+  // CHECK-CC8: COMPLETION: Pattern : member2(<#args#>
   int member1, member2;
 };
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -1656,7 +1656,17 @@
 && II->getObjCKeywordID() == tok::objc_not_keyword) {
   // Return the code-completion token.
   Result.setKind(tok::code_completion);
-  cutOffLexing();
+  // Skip the code-completion char and all immediate identifier characters.
+  // This ensures we get consistent behavior when completing at any point in
+  // an identifier (i.e. at the start, in the middle, at the end). Note that
+  // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code
+  // simpler.
+  assert(*CurPtr == 0 && "Completion character must be 0");
+  ++CurPtr;
+  assert(CurPtr < BufferEnd && "eof at completion point");
+  while (isIdentifierBody(*CurPtr))
+++CurPtr;
+  BufferPtr = CurPtr;
   return true;
 }
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-27 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 139920.
aheejin added a comment.

- Comment fix


Repository:
  rC Clang

https://reviews.llvm.org/D44931

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGCleanup.cpp
  lib/CodeGen/CGCleanup.h
  lib/CodeGen/CGException.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/wasm-eh.cpp

Index: test/CodeGenCXX/wasm-eh.cpp
===
--- /dev/null
+++ test/CodeGenCXX/wasm-eh.cpp
@@ -0,0 +1,346 @@
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+
+void may_throw();
+void dont_throw() noexcept;
+
+struct Cleanup {
+  ~Cleanup() { dont_throw(); }
+};
+
+// Multiple catch clauses w/o catch-all
+void test0() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (double) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: define void @_Z5test0v() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+
+// CHECK:   %[[INT_ALLOCA:.*]] = alloca i32
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label %[[NORMAL_BB:.*]] unwind label %[[CATCHDISPATCH_BB:.*]]
+
+// CHECK: [[CATCHDISPATCH_BB]]:
+// CHECK-NEXT:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)]
+// CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.get.exception()
+// CHECK-NEXT:   store i8* %[[EXN]], i8** %exn.slot
+// CHECK-NEXT:   %[[SELECTOR:.*]] = call i32 @llvm.wasm.get.ehselector()
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_INT_BB:.*]], label %[[CATCH_FALLTHROUGH_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK-NEXT:   %[[EXN:.*]] = load i8*, i8** %exn.slot
+// CHECK-NEXT:   %[[ADDR:.*]] = call i8* @__cxa_begin_catch(i8* %[[EXN]]) {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   %[[ADDR_CAST:.*]] = bitcast i8* %[[ADDR]] to i32*
+// CHECK-NEXT:   %[[INT_VAL:.*]] = load i32, i32* %[[ADDR_CAST]]
+// CHECK-NEXT:   store i32 %[[INT_VAL]], i32* %[[INT_ALLOCA]]
+// CHECK-NEXT:   call void @_Z10dont_throwv() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   call void @__cxa_end_catch() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB0:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB0]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB:.*]]
+
+// CHECK: [[CATCH_FALLTHROUGH_BB]]
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTId to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_FLOAT_BB:.*]], label %[[RETHROW_BB:.*]]
+
+// CHECK: [[CATCH_FLOAT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB1:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB1]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB]]
+
+// CHECK: [[RETHROW_BB]]:
+// CHECK-NEXT:   call void @__cxa_rethrow() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   unreachable
+
+
+// Single catch-all
+void test1() {
+  try {
+may_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CATCH-LABEL: @_Z5test1v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* null]
+// CHECK:   br label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Multiple catch clauses w/ catch-all
+void test2() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: @_Z5test2v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* null]
+// CHECK:   br i1 %{{.*}}, label %[[CATCH_INT_BB:.*]], label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Cleanup
+void test3() {
+  Cleanup c;
+  may_throw();
+}
+
+// CHECK-LABEL: @_Z5test3v()
+
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label {{.*}} unwind label %[[EHCLEANUP_BB:.*]]
+
+// CHECK: 

[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-27 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin created this revision.
aheejin added reviewers: majnemer, dschuff.
Herald added subscribers: cfe-commits, sunfish, jgravelle-google, sbc100, jfb.

Because wasm control flow needs to be structured, using WinEH
instructions to support wasm EH brings several benefits. This patch
makes wasm EH uses Windows EH instructions, with some changes:

1. Because wasm uses a single catch block to catch all C++ exceptions, this 
merges all catch clauses into a single catchpad, within which we test the EH 
selector as in Itanium EH.
2. Generates a call to `__clang_call_terminate` in case a cleanup throws. Wasm 
does not have a runtime to handle this.
3. In case there is no catch-all clause, inserts a call to `__cxa_rethrow` at 
the end of a catchpad in order to unwind to an enclosing EH scope.


Repository:
  rC Clang

https://reviews.llvm.org/D44931

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGCleanup.cpp
  lib/CodeGen/CGCleanup.h
  lib/CodeGen/CGException.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/wasm-eh.cpp

Index: test/CodeGenCXX/wasm-eh.cpp
===
--- /dev/null
+++ test/CodeGenCXX/wasm-eh.cpp
@@ -0,0 +1,346 @@
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+
+void may_throw();
+void dont_throw() noexcept;
+
+struct Cleanup {
+  ~Cleanup() { dont_throw(); }
+};
+
+// Multiple catch clauses w/o catch-all
+void test0() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (double) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: define void @_Z5test0v() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+
+// CHECK:   %[[INT_ALLOCA:.*]] = alloca i32
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label %[[NORMAL_BB:.*]] unwind label %[[CATCHDISPATCH_BB:.*]]
+
+// CHECK: [[CATCHDISPATCH_BB]]:
+// CHECK-NEXT:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)]
+// CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.get.exception()
+// CHECK-NEXT:   store i8* %[[EXN]], i8** %exn.slot
+// CHECK-NEXT:   %[[SELECTOR:.*]] = call i32 @llvm.wasm.get.ehselector()
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_INT_BB:.*]], label %[[CATCH_FALLTHROUGH_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK-NEXT:   %[[EXN:.*]] = load i8*, i8** %exn.slot
+// CHECK-NEXT:   %[[ADDR:.*]] = call i8* @__cxa_begin_catch(i8* %[[EXN]]) {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   %[[ADDR_CAST:.*]] = bitcast i8* %[[ADDR]] to i32*
+// CHECK-NEXT:   %[[INT_VAL:.*]] = load i32, i32* %[[ADDR_CAST]]
+// CHECK-NEXT:   store i32 %[[INT_VAL]], i32* %[[INT_ALLOCA]]
+// CHECK-NEXT:   call void @_Z10dont_throwv() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   call void @__cxa_end_catch() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB0:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB0]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB:.*]]
+
+// CHECK: [[CATCH_FALLTHROUGH_BB]]
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTId to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_FLOAT_BB:.*]], label %[[RETHROW_BB:.*]]
+
+// CHECK: [[CATCH_FLOAT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB1:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB1]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB]]
+
+// CHECK: [[RETHROW_BB]]:
+// CHECK-NEXT:   call void @__cxa_rethrow() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   unreachable
+
+
+// Single catch-all
+void test1() {
+  try {
+may_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CATCH-LABEL: @_Z5test1v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* null]
+// CHECK:   br label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Multiple catch clauses w/ catch-all
+void test2() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: @_Z5test2v()
+
+// CHECK:   

r328623 - Move a ref-counted pointer instead of copying it. NFC.

2018-03-27 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Mar 27 07:02:06 2018
New Revision: 328623

URL: http://llvm.org/viewvc/llvm-project?rev=328623=rev
Log:
Move a ref-counted pointer instead of copying it. NFC.

Modified:
cfe/trunk/lib/Tooling/Tooling.cpp

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=328623=328622=328623=diff
==
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Tue Mar 27 07:02:06 2018
@@ -361,7 +361,7 @@ ClangTool::ClangTool(const CompilationDa
  IntrusiveRefCntPtr BaseFS)
 : Compilations(Compilations), SourcePaths(SourcePaths),
   PCHContainerOps(std::move(PCHContainerOps)),
-  OverlayFileSystem(new vfs::OverlayFileSystem(BaseFS)),
+  OverlayFileSystem(new vfs::OverlayFileSystem(std::move(BaseFS))),
   InMemoryFileSystem(new vfs::InMemoryFileSystem),
   Files(new FileManager(FileSystemOptions(), OverlayFileSystem)) {
   OverlayFileSystem->pushOverlay(InMemoryFileSystem);


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


[clang-tools-extra] r328622 - [clang-move] Fix test failing due to clang-format change

2018-03-27 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Tue Mar 27 06:39:33 2018
New Revision: 328622

URL: http://llvm.org/viewvc/llvm-project?rev=328622=rev
Log:
[clang-move] Fix test failing due to clang-format change

r328621 reverted the removal of empty lines before the closing `}` in
namespaces.

Modified:
clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp

Modified: clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp?rev=328622=328621=328622=diff
==
--- clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-move/move-used-helper-decls.cpp Tue Mar 
27 06:39:33 2018
@@ -335,6 +335,7 @@
 // CHECK-NEW-H-NEXT: void Fun1();
 // CHECK-NEW-H-SAME: {{[[:space:]]}}
 // CHECK-NEW-H-NEXT: inline void Fun2() {}
+// CHECK-NEW-H-SAME: {{[[:space:]]}}
 // CHECK-NEW-H-NEXT: } // namespace a
 
 
@@ -412,6 +413,7 @@
 // CHECK-NEW-CPP-NEXT: }
 // CHECK-NEW-CPP-SAME: {{[[:space:]]}}
 // CHECK-NEW-CPP-NEXT: void Fun1() { HelperFun5(); }
+// CHECK-NEW-CPP-SAME: {{[[:space:]]}}
 // CHECK-NEW-CPP-NEXT: } // namespace a
 // CHECK-NEW-CPP-SAME: {{[[:space:]]}}
 // CHECK-NEW-CPP-NEXT: namespace b {


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


[PATCH] D44927: Enable msan unconditionally on Linux

2018-03-27 Thread vit9696 via Phabricator via cfe-commits
vit9696 created this revision.
vit9696 added a reviewer: eugenis.
Herald added a subscriber: cfe-commits.

Memeory sanitizer compatibility are already done in 
MemorySanitizer::doInitialization. It verifies whether the necessary offsets 
exist and bails out if not. For this reason it is no good to duplicate two 
checks in two projects. This patch removes clang check and postpones msan 
compatibility validation till MemorySanitizer::doInitialization.

Another reason for this patch is to allow using msan with any CPU (given 
compatible runtime) and custom mapping provided via the arguments added by 
https://reviews.llvm.org/D44926.


Repository:
  rC Clang

https://reviews.llvm.org/D44927

Files:
  lib/Driver/ToolChains/Linux.cpp


Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -863,16 +863,15 @@
   Res |= SanitizerKind::Fuzzer;
   Res |= SanitizerKind::FuzzerNoLink;
   Res |= SanitizerKind::KernelAddress;
+  Res |= SanitizerKind::Memory;
   Res |= SanitizerKind::Vptr;
   Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
 Res |= SanitizerKind::Thread;
-  if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64)
-Res |= SanitizerKind::Memory;
   if (IsX86_64 || IsMIPS64)
 Res |= SanitizerKind::Efficiency;
   if (IsX86 || IsX86_64)


Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -863,16 +863,15 @@
   Res |= SanitizerKind::Fuzzer;
   Res |= SanitizerKind::FuzzerNoLink;
   Res |= SanitizerKind::KernelAddress;
+  Res |= SanitizerKind::Memory;
   Res |= SanitizerKind::Vptr;
   Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
 Res |= SanitizerKind::Thread;
-  if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64)
-Res |= SanitizerKind::Memory;
   if (IsX86_64 || IsMIPS64)
 Res |= SanitizerKind::Efficiency;
   if (IsX86 || IsX86_64)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >