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

2018-02-01 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: test/SemaCXX/constexpr-default-arg.cpp:3
+
+// expected-no-diagnostics
+

Down the line, it won't be obvious *what* this testcase is checking.
At the very least wrap it into `namespace rdar_problem_36505742 {}`


https://reviews.llvm.org/D42776



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-02-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In https://reviews.llvm.org/D41102#994311, @juliehockett wrote:

> I'm going to take a stab at refactoring the serialization part of this next 
> -- rather than keeping it all in memory and dumping it at the end, it should 
> serialize as it goes and do some sort of reduce at the end. I'm currently 
> thinking of writing it out to a file as it goes, and then reading and 
> reducing from there -- thoughts?


Sounds awesome :-) Some thoughts on structure (sorry for the rant - clangd's 
indexer has a similar problem so I've been thinking about this).

This neatly separates the problem out into

- "business logic" for map and reduce - these are basically pure functions
- imperative frameworky stuff: serializing/deserializing, grouping map keys 
together, running threadpools

Sadly we don't have a generic implementation of the frameworky part in 
libtooling I think, so you'll probably end up writing the bits you need in 
clang-doc.
There is `ExecutionContext` in Tooling/Execution.h, which allows you to report 
KV pairs, and loop over them afterwards, which models map output (must be 
serialized as strings).

Still I think there's value in separating out the two layers:

- conceptual clarity
- testing (the pure functions are nice to test)
- one can hook up the mapper/reducer to hadoop, or google's internal 
infrastructure, or ...
- it can inspire and benefit from someone writing a reusable upstream MR API

So maybe the API could look something roughly like:

`newFrontendActionFactory(DocSink)` returns clang-doc's extractor part (the 
mapper, i.e. most of this patch)
`DocSink` is a class with a bunch of methods like `emitNamespaceInfo(StringRef 
Name, NSInfo)`. This adapts to the MR machinery: it could write to 
ExecutionContext, or files on disk as you suggest.
Merging provided via classes like `class MergeNS { MergeNS(StringRef Name); 
void add(NSInfo); NSInfo finish(); }` These would be invoked by the MR 
machinery (for now, just code that iterates over the ExecutionContext or files 
on disk).

In this case, you could test the mapper in isolation by writing a small tool 
that just runs the mapper over some files, gathers the result, and dumps it as 
YAML. The reducer and the MR driver wouldn't need to be part of this patch.

Anyway, of course you may want to take this in a different direction - just 
some ideas.




Comment at: tools/clang-doc/ClangDoc.h:29
+struct ClangDocContext {
+  // Which format in which to emit representation.
+  OutFormat EmitFormat;

juliehockett wrote:
> sammccall wrote:
> > Is this the intermediate representation referred to in the design doc, or 
> > the final output format?
> > 
> > If the former, why two formats rather than picking one?
> > YAML is nice for being usable by out-of-tree tools (though not as nice as 
> > JSON). But it seems like providing YAML as a trivial backend format would 
> > fit well?
> > Bitcode is presumably more space-efficient - if this is significant in 
> > practice it seems like a better choice.
> That's the idea -- for developing purposes, I wrote up the YAML output first 
> for this patch, and there will be a follow-on patch expanding the 
> bitcode/binary output. I've updated the flags to default to the binary, with 
> an option to dump the yaml (rather than the other way around).
What's still not clear to me is: is YAML a) a "real" intermediate format, or b) 
just a debug representation?

I would suggest for orthogonality that there only be one intermediate format, 
and that any debug version be generated from it. In practice I guess this means:
 - the reporter builds the in-memory representation
 - you can serialize/deserialize memory representation to the IR (bitcode)
 - you can serialize memory representation to debug representation (YAML) but 
not parse
 - maybe the clang-doc core should *only* know about IR, and YAML should be 
produced in the same way e.g. HTML would be?

This does pose a short-term problem: the canonical IR is bitcode, we need YAML 
for the lit tests, and we don't have the decoder/transformer part yet. This 
could be solved either by using YAML as the IR *for now* and switching later, 
or by adding a simple decoder now.
Either way it points to the *reporter* not having an output format option, and 
having to support two formats.

WDYT? I might be missing something here.



Comment at: tools/clang-doc/ClangDoc.h:33
+
+class ClangDocVisitor : public RecursiveASTVisitor {
+public:

juliehockett wrote:
> jakehehrlich wrote:
> > sammccall wrote:
> > > This API makes essentially everything public. Is that the intent?
> > > 
> > > It seems like `ClangDocVisitor` is a detail, and the operation you want 
> > > to expose is "extract doc from this AST into this reporter" or maybe 
> > > "create an AST consumer that feeds this reporter".
> > > 
> > > It would be useful to have an API to extract documentation from 
> > > individual AST nodes (e.g.

[PATCH] D42742: [clangd] Use pthread instead of thread_local to support more runtimes.

2018-02-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42742



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


Re: r323935 - PR36181: Teach CodeGen to properly ignore requests to emit dependent entities.

2018-02-01 Thread Hans Wennborg via cfe-commits
On Thu, Feb 1, 2018 at 2:42 AM, Richard Smith  wrote:

> On 31 January 2018 at 16:42, Shoaib Meenai via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Is this viable for backporting to 6.0? It fixes a bug that's been hit in
>> various forms by quite a few people: https://bugs.llvm.org/show_bug
>> .cgi?id=36181, https://bugs.llvm.org/show_bug.cgi?id=35473, and
>> https://bugs.llvm.org/show_bug.cgi?id=35939.
>>
>
> I'd be OK with that once it's had a few days to work its way through
> various automated build systems.
>

Sounds good. I'll merge when it's baked a bit.



>
>
>>
>> *From: *cfe-commits  on behalf of
>> Richard Smith via cfe-commits 
>> *Reply-To: *Richard Smith 
>> *Date: *Wednesday, January 31, 2018 at 4:32 PM
>> *To: *"cfe-commits@lists.llvm.org" 
>> *Subject: *r323935 - PR36181: Teach CodeGen to properly ignore requests
>> to emit dependent entities.
>>
>>
>>
>> Author: rsmith
>>
>> Date: Wed Jan 31 16:28:36 2018
>>
>> New Revision: 323935
>>
>>
>>
>> URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org
>> _viewvc_llvm-2Dproject-3Frev-3D323935-26view-3Drev&d=DwIGaQ
>> &c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=lpLH9VU
>> hmNJcmdOGGUS4JH7kl-0dHB_UbZJavDZFar8&s=gXiqdj7RcmFitXx
>> zq_T6trCkulPJ1hKO9JTh4N1W1Ds&e=
>>
>> Log:
>>
>> PR36181: Teach CodeGen to properly ignore requests to emit dependent
>> entities.
>>
>>
>>
>> Previously, friend function definitions within class templates slipped
>> through
>>
>> the gaps and caused the MS mangler to assert.
>>
>>
>>
>> Added:
>>
>> cfe/trunk/test/CodeGenCXX/microsoft-abi-emit-dependent.cpp
>>
>> Modified:
>>
>> cfe/trunk/include/clang/AST/DeclBase.h
>>
>> cfe/trunk/lib/AST/DeclBase.cpp
>>
>> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>>
>>
>>
>> Modified: cfe/trunk/include/clang/AST/DeclBase.h
>>
>> URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org
>> _viewvc_llvm-2Dproject_cfe_trunk_include_clang_AST_DeclBase.
>> h-3Frev-3D323935-26r1-3D323934-26r2-3D323935-26view-
>> 3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKe
>> TWOMw&m=lpLH9VUhmNJcmdOGGUS4JH7kl-0dHB_UbZJavDZFar8&s=IdB02f
>> 1U8VHa1i4Dvuj1BkcyoWf9sYvY3xE1L8bzfM0&e=
>>
>> 
>> ==
>>
>> --- cfe/trunk/include/clang/AST/DeclBase.h (original)
>>
>> +++ cfe/trunk/include/clang/AST/DeclBase.h Wed Jan 31 16:28:36 2018
>>
>> @@ -836,6 +836,10 @@ public:
>>
>>void setLexicalDeclContext(DeclContext *DC);
>>
>> +  /// Determine whether this declaration is a templated entity (whether
>> it is
>>
>> +  // within the scope of a template parameter).
>>
>> +  bool isTemplated() const;
>>
>> +
>>
>>/// isDefinedOutsideFunctionOrMethod - This predicate returns true if
>> this
>>
>>/// scoped decl is defined outside the current function or
>> method.  This is
>>
>>/// roughly global variables and functions, but also handles enums
>> (which
>>
>>
>>
>> Modified: cfe/trunk/lib/AST/DeclBase.cpp
>>
>> URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org
>> _viewvc_llvm-2Dproject_cfe_trunk_lib_AST_DeclBase.cpp-3Frev-
>> 3D323935-26r1-3D323934-26r2-3D323935-26view-3Ddiff&d=DwIGa
>> Q&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=lpLH9V
>> UhmNJcmdOGGUS4JH7kl-0dHB_UbZJavDZFar8&s=3WgES9JYNm2mJaP
>> KUnRnaFndAGpGnj0AJ9kR5ARgxao&e=
>>
>> 
>> ==
>>
>> --- cfe/trunk/lib/AST/DeclBase.cpp (original)
>>
>> +++ cfe/trunk/lib/AST/DeclBase.cpp Wed Jan 31 16:28:36 2018
>>
>> @@ -236,10 +236,23 @@ TemplateDecl *Decl::getDescribedTemplate
>>
>>  return RD->getDescribedClassTemplate();
>>
>>else if (auto *VD = dyn_cast(this))
>>
>>  return VD->getDescribedVarTemplate();
>>
>> +  else if (auto *AD = dyn_cast(this))
>>
>> +return AD->getDescribedAliasTemplate();
>>
>>return nullptr;
>>
>> }
>>
>> +bool Decl::isTemplated() const {
>>
>> +  // A declaration is dependent if it is a template or a template
>> pattern, or
>>
>> +  // is within (lexcially for a friend, semantically otherwise) a
>> dependent
>>
>> +  // context.
>>
>> +  // FIXME: Should local extern declarations be treated like friends?
>>
>> +  if (auto *AsDC = dyn_cast(this))
>>
>> +return AsDC->isDependentContext();
>>
>> +  auto *DC = getFriendObjectKind() ? getLexicalDeclContext() :
>> getDeclContext();
>>
>> +  return DC->isDependentContext() || isTemplateDecl() ||
>> getDescribedTemplate();
>>
>> +}
>>
>> +
>>
>> const DeclContext *Decl::getParentFunctionOrMethod() const {
>>
>>for (const DeclContext *DC = getDeclContext();
>>
>> DC && !DC->isTranslationUnit() && !DC->isNamespace();
>>
>>
>>
>> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>>
>> URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org
>> _viewvc_llvm-2Dproject_cfe_trunk_lib_CodeGen_CodeGenModule.
>> cpp-3Frev-3D323935-26r1-3D323934-26r2-3D323935-26view-
>> 3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o

[PATCH] D39571: [clangd] DidChangeConfiguration Notification

2018-02-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdLSPServer.cpp:78
 {"documentHighlightProvider", true},
+{"configurationChangeProvider", true},
 {"renameProvider", true},

simark wrote:
> ilya-biryukov wrote:
> > simark wrote:
> > > Nebiroth wrote:
> > > > simark wrote:
> > > > > I find `configurationChangeProvider` a bit weird.  It makes it sound 
> > > > > like clangd can provide configuration changes.  In reality, it can 
> > > > > accept configuration changes.  So I think this should be named 
> > > > > something else.
> > > > Agreed, perhaps configurationChangeManager would be more appropriate 
> > > > then?
> > > I'm thinking of removing it for the time being.  Since it's not defined 
> > > in the protocol what types of configuration changes exist (it's specific 
> > > to each language server), it not very useful to simply advertise that we 
> > > support configuration changes.  We would need to advertise that we 
> > > support compilation database changes in particular.  I think this can be 
> > > done later.
> > `"configurationChangeProvider"` is not in the LSP, right?
> > There's `experimental` field in the specification, let's put it under that 
> > field if you want to advertise that clangd supports this spec to your 
> > clients.
> I've removed it for now, we can add it later.  We should think about how to 
> express what we support.  It's not enough to say we support the 
> `didChangeConfiguration` notification, we should also express what element of 
> configuration we support (the location of the compile commands directory, in 
> this case).
SG. Let's not add extra stuff not in the LSP if the clients can live without it.



Comment at: clangd/ClangdLSPServer.cpp:302
 
+// FIXME: This function needs to be properly tested.
+void ClangdLSPServer::onChangeConfiguration(

simark wrote:
> simark wrote:
> > ilya-biryukov wrote:
> > > simark wrote:
> > > > ilya-biryukov wrote:
> > > > > simark wrote:
> > > > > > ilya-biryukov wrote:
> > > > > > > Are you planning to to address this FIXME before checking the 
> > > > > > > code in?
> > > > > > Following what you said here:
> > > > > > 
> > > > > > https://reviews.llvm.org/D39571?id=124024#inline-359345
> > > > > > 
> > > > > > I have not really looked into what was wrong with the test, and 
> > > > > > what is missing in the infrastructure to make it work.  But I 
> > > > > > assumed that the situation did not change since then.  Can you 
> > > > > > enlighten me on what the problem was, and what is missing?
> > > > > We usually write unittests for that kind of thing, since they allow 
> > > > > to plug an in-memory filesystem, but we only test `ClangdServer` 
> > > > > (examples are in `unittests/clangd/ClangdTests.cpp`). 
> > > > > `ClangdLSPServer` does not allow to plug in a virtual filesystem 
> > > > > (vfs). Even if we add vfs, it's still hard to unit-test because we'll 
> > > > > have to match the json input/output directly.
> > > > > 
> > > > > This leaves us with an option of a lit test that runs `clangd` 
> > > > > directly, similar to tests in `test/clangd`.
> > > > > The lit test would need to create a temporary directory, create 
> > > > > proper `compile_commands.json` there, then send the LSP commands with 
> > > > > the path to the test to clangd.
> > > > > One major complication is that in LSP we have to specify the size of 
> > > > > each message, but in our case the size would change depending on 
> > > > > created temp path. It means we'll have to patch the test input to 
> > > > > setup proper paths and message sizes.
> > > > > If we choose to go down this path, 
> > > > > `clang-tools-extra/test/clang-tidy/vfsoverlay.cpp` does a similar 
> > > > > setup (create temp-dir, patch up some configuration files to point 
> > > > > into the temp directory, etc) and could be used as a starting point.
> > > > > 
> > > > > It's not impossible to write that test, it's just a bit involved. 
> > > > > Having a test would be nice, though, to ensure we don't break this 
> > > > > method while doing other things. Especially given that this 
> > > > > functionality is not used anywhere in clangd.
> > > > > We usually write unittests for that kind of thing, since they allow 
> > > > > to plug an in-memory filesystem, but we only test ClangdServer 
> > > > > (examples are in unittests/clangd/ClangdTests.cpp). ClangdLSPServer 
> > > > > does not allow to plug in a virtual filesystem (vfs). Even if we add 
> > > > > vfs, it's still hard to unit-test because we'll have to match the 
> > > > > json input/output directly.
> > > > 
> > > > What do you mean by "we'll have to match the json input/output 
> > > > directly"?  That we'll have to match the complete JSON output 
> > > > textually?  Couldn't the test parse the JSON into some data structures, 
> > > > then we could assert specific things, like that this particular field 
> > > > is

[PATCH] D42785: [Analyzer] Fix a typo in `ExprEngine::VisitMemberExpr`

2018-02-01 Thread Henry Wong via Phabricator via cfe-commits
MTC created this revision.
MTC added reviewers: NoQ, dcoughlin.
Herald added subscribers: cfe-commits, a.sidorin, szepet, xazax.hun.
Herald added a reviewer: george.karpenkov.
MTC edited the summary of this revision.

`VisitCommonDeclRefExpr()` should accept the ExplodedNode in `CheckedSet` as an 
argument, rather than `Pred`.


Repository:
  rC Clang

https://reviews.llvm.org/D42785

Files:
  lib/StaticAnalyzer/Core/ExprEngine.cpp


Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2251,16 +2251,15 @@
   ExplodedNodeSet CheckedSet;
   getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, M, *this);
 
-  ExplodedNodeSet EvalSet;
-  ValueDecl *Member = M->getMemberDecl();
+  ExplodedNodeSet EvalSet;  
+  ValueDecl *Member = M->getMemberDecl();  
 
   // Handle static member variables and enum constants accessed via
   // member syntax.
-  if (isa(Member) || isa(Member)) {
-ExplodedNodeSet Dst;
+  if (isa(Member) || isa(Member)) {
 for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = 
CheckedSet.end();
  I != E; ++I) {
-  VisitCommonDeclRefExpr(M, Member, Pred, EvalSet);
+  VisitCommonDeclRefExpr(M, Member, *I, EvalSet);
 }
   } else {
 StmtNodeBuilder Bldr(CheckedSet, EvalSet, *currBldrCtx);


Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2251,16 +2251,15 @@
   ExplodedNodeSet CheckedSet;
   getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, M, *this);
 
-  ExplodedNodeSet EvalSet;
-  ValueDecl *Member = M->getMemberDecl();
+  ExplodedNodeSet EvalSet;  
+  ValueDecl *Member = M->getMemberDecl();  
 
   // Handle static member variables and enum constants accessed via
   // member syntax.
-  if (isa(Member) || isa(Member)) {
-ExplodedNodeSet Dst;
+  if (isa(Member) || isa(Member)) {
 for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
  I != E; ++I) {
-  VisitCommonDeclRefExpr(M, Member, Pred, EvalSet);
+  VisitCommonDeclRefExpr(M, Member, *I, EvalSet);
 }
   } else {
 StmtNodeBuilder Bldr(CheckedSet, EvalSet, *currBldrCtx);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r323949 - [clangd] Use pthread instead of thread_local to support more runtimes.

2018-02-01 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Feb  1 02:01:25 2018
New Revision: 323949

URL: http://llvm.org/viewvc/llvm-project?rev=323949&view=rev
Log:
[clangd] Use pthread instead of thread_local to support more runtimes.

Summary:
thread_local has nice syntax and semantics, but requires __cxa_thread_atexit,
and some not-ancient runtime libraries don't provide it.
The clang-x86_64-linux-selfhost-modules buildbot is one example :-)

It works on windows, and the other platforms clang-tools-extra supports should
all have the relevant pthread API. So we just use that if it's available,
falling back to thread_local (so if a platform has neither, we'll fail to link).

The fallback should really be the other way, that would require cmake changes.

Reviewers: ilya-biryukov, bkramer

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/Context.cpp

Modified: clang-tools-extra/trunk/clangd/Context.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Context.cpp?rev=323949&r1=323948&r2=323949&view=diff
==
--- clang-tools-extra/trunk/clangd/Context.cpp (original)
+++ clang-tools-extra/trunk/clangd/Context.cpp Thu Feb  1 02:01:25 2018
@@ -8,8 +8,48 @@
 //===-===//
 
 #include "Context.h"
+#include "llvm/Config/config.h"
 #include 
 
+// The thread-local Context is scoped in a function to avoid init-order issues.
+// It's created by currentContext() when first needed.
+
+#ifdef HAVE_PTHREAD_GETSPECIFIC
+// We'd love to use thread_local everywhere.
+// It requires support from the runtime: __cxa_thread_atexit.
+// Rather than detect this, we use the pthread API where available.
+#include 
+static clang::clangd::Context ¤tContext() {
+  using clang::clangd::Context;
+  static pthread_key_t CtxKey;
+
+  // Once (across threads), set up pthread TLS for Context, and its destructor.
+  static int Dummy = [] { // Create key only once, for all threads.
+if (auto Err = pthread_key_create(&CtxKey, /*destructor=*/+[](void *Ctx) {
+  delete reinterpret_cast(Ctx);
+}))
+  llvm_unreachable(strerror(Err));
+return 0;
+  }();
+  (void)Dummy;
+
+  // Now grab the current context from TLS, and create it if it doesn't exist.
+  void *Ctx = pthread_getspecific(CtxKey);
+  if (!Ctx) {
+Ctx = new Context();
+if (auto Err = pthread_setspecific(CtxKey, Ctx))
+  llvm_unreachable(strerror(Err));
+  }
+  return *reinterpret_cast(Ctx);
+}
+#else
+// Only supported platform without pthread is windows, and thread_local works.
+static clang::clangd::Context ¤tContext() {
+  static thread_local auto C = clang::clangd::Context::empty();
+  return C;
+}
+#endif
+
 namespace clang {
 namespace clangd {
 
@@ -20,13 +60,6 @@ Context::Context(std::shared_ptrhttp://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42742: [clangd] Use pthread instead of thread_local to support more runtimes.

2018-02-01 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL323949: [clangd] Use pthread instead of thread_local to 
support more runtimes. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42742

Files:
  clang-tools-extra/trunk/clangd/Context.cpp


Index: clang-tools-extra/trunk/clangd/Context.cpp
===
--- clang-tools-extra/trunk/clangd/Context.cpp
+++ clang-tools-extra/trunk/clangd/Context.cpp
@@ -8,8 +8,48 @@
 //===-===//
 
 #include "Context.h"
+#include "llvm/Config/config.h"
 #include 
 
+// The thread-local Context is scoped in a function to avoid init-order issues.
+// It's created by currentContext() when first needed.
+
+#ifdef HAVE_PTHREAD_GETSPECIFIC
+// We'd love to use thread_local everywhere.
+// It requires support from the runtime: __cxa_thread_atexit.
+// Rather than detect this, we use the pthread API where available.
+#include 
+static clang::clangd::Context ¤tContext() {
+  using clang::clangd::Context;
+  static pthread_key_t CtxKey;
+
+  // Once (across threads), set up pthread TLS for Context, and its destructor.
+  static int Dummy = [] { // Create key only once, for all threads.
+if (auto Err = pthread_key_create(&CtxKey, /*destructor=*/+[](void *Ctx) {
+  delete reinterpret_cast(Ctx);
+}))
+  llvm_unreachable(strerror(Err));
+return 0;
+  }();
+  (void)Dummy;
+
+  // Now grab the current context from TLS, and create it if it doesn't exist.
+  void *Ctx = pthread_getspecific(CtxKey);
+  if (!Ctx) {
+Ctx = new Context();
+if (auto Err = pthread_setspecific(CtxKey, Ctx))
+  llvm_unreachable(strerror(Err));
+  }
+  return *reinterpret_cast(Ctx);
+}
+#else
+// Only supported platform without pthread is windows, and thread_local works.
+static clang::clangd::Context ¤tContext() {
+  static thread_local auto C = clang::clangd::Context::empty();
+  return C;
+}
+#endif
+
 namespace clang {
 namespace clangd {
 
@@ -20,13 +60,6 @@
 
 Context Context::clone() const { return Context(DataPtr); }
 
-// The thread-local Context is scoped in a function to avoid
-// initialization-order issues. It's created when first needed.
-static Context ¤tContext() {
-  static thread_local Context C = Context::empty();
-  return C;
-}
-
 const Context &Context::current() { return currentContext(); }
 
 Context Context::swapCurrent(Context Replacement) {


Index: clang-tools-extra/trunk/clangd/Context.cpp
===
--- clang-tools-extra/trunk/clangd/Context.cpp
+++ clang-tools-extra/trunk/clangd/Context.cpp
@@ -8,8 +8,48 @@
 //===-===//
 
 #include "Context.h"
+#include "llvm/Config/config.h"
 #include 
 
+// The thread-local Context is scoped in a function to avoid init-order issues.
+// It's created by currentContext() when first needed.
+
+#ifdef HAVE_PTHREAD_GETSPECIFIC
+// We'd love to use thread_local everywhere.
+// It requires support from the runtime: __cxa_thread_atexit.
+// Rather than detect this, we use the pthread API where available.
+#include 
+static clang::clangd::Context ¤tContext() {
+  using clang::clangd::Context;
+  static pthread_key_t CtxKey;
+
+  // Once (across threads), set up pthread TLS for Context, and its destructor.
+  static int Dummy = [] { // Create key only once, for all threads.
+if (auto Err = pthread_key_create(&CtxKey, /*destructor=*/+[](void *Ctx) {
+  delete reinterpret_cast(Ctx);
+}))
+  llvm_unreachable(strerror(Err));
+return 0;
+  }();
+  (void)Dummy;
+
+  // Now grab the current context from TLS, and create it if it doesn't exist.
+  void *Ctx = pthread_getspecific(CtxKey);
+  if (!Ctx) {
+Ctx = new Context();
+if (auto Err = pthread_setspecific(CtxKey, Ctx))
+  llvm_unreachable(strerror(Err));
+  }
+  return *reinterpret_cast(Ctx);
+}
+#else
+// Only supported platform without pthread is windows, and thread_local works.
+static clang::clangd::Context ¤tContext() {
+  static thread_local auto C = clang::clangd::Context::empty();
+  return C;
+}
+#endif
+
 namespace clang {
 namespace clangd {
 
@@ -20,13 +60,6 @@
 
 Context Context::clone() const { return Context(DataPtr); }
 
-// The thread-local Context is scoped in a function to avoid
-// initialization-order issues. It's created when first needed.
-static Context ¤tContext() {
-  static thread_local Context C = Context::empty();
-  return C;
-}
-
 const Context &Context::current() { return currentContext(); }
 
 Context Context::swapCurrent(Context Replacement) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42035: [clang-format] Fixup #include guard indents after parseFile()

2018-02-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Looks good! Just some comments for the include guard states would be helpful.




Comment at: lib/Format/UnwrappedLineParser.h:259
+IG_Rejected,
+  };
+

Please put a short comment explaining each of these states.


Repository:
  rC Clang

https://reviews.llvm.org/D42035



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


[PATCH] D42684: clang-format: Allow optimizer to break template declaration.

2018-02-01 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 132341.
Typz added a comment.

If the template declaration spans multiple lines, force wrap before the 
function/class declaration


Repository:
  rC Clang

https://reviews.llvm.org/D42684

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5367,7 +5367,7 @@
"const typename  aaa);");
 
   FormatStyle AlwaysBreak = getLLVMStyle();
-  AlwaysBreak.AlwaysBreakTemplateDeclarations = true;
+  AlwaysBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_All;
   verifyFormat("template \nclass C {};", AlwaysBreak);
   verifyFormat("template \nvoid f();", AlwaysBreak);
   verifyFormat("template \nvoid f() {}", AlwaysBreak);
@@ -5385,6 +5385,32 @@
"public:\n"
"  E *f();\n"
"};");
+
+  FormatStyle NeverBreak = getLLVMStyle();
+  NeverBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_None;
+  verifyFormat("template  class C {};", NeverBreak);
+  verifyFormat("template  void f();", NeverBreak);
+  verifyFormat("template  void f() {}", NeverBreak);
+  verifyFormat("template \nvoid foo(aa ) {}",
+   NeverBreak);
+  verifyFormat("void aaa(\n"
+   "ccc);",
+   NeverBreak);
+  verifyFormat("template  class Fooo,\n"
+   "  template  class Baaar>\n"
+   "struct C {};",
+   NeverBreak);
+  verifyFormat("template  // T can be A, B or C.\n"
+   "struct C {};",
+   NeverBreak);
+  verifyFormat("template  class A {\n"
+   "public:\n"
+   "  E *f();\n"
+   "};", NeverBreak);
+  NeverBreak.PenaltyBreakTemplateDeclaration = 100;
+  verifyFormat("template  void\nfoo(aa ) {}",
+   NeverBreak);
 }
 
 TEST_F(FormatTest, WrapsTemplateParameters) {
@@ -10166,7 +10192,6 @@
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
-  CHECK_PARSE_BOOL(AlwaysBreakTemplateDeclarations);
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
@@ -10229,6 +10254,8 @@
   PenaltyBreakAssignment, 1234u);
   CHECK_PARSE("PenaltyBreakBeforeFirstCallParameter: 1234",
   PenaltyBreakBeforeFirstCallParameter, 1234u);
+  CHECK_PARSE("PenaltyBreakTemplateDeclaration: 1234",
+  PenaltyBreakTemplateDeclaration, 1234u);
   CHECK_PARSE("PenaltyExcessCharacter: 1234", PenaltyExcessCharacter, 1234u);
   CHECK_PARSE("PenaltyReturnTypeOnItsOwnLine: 1234",
   PenaltyReturnTypeOnItsOwnLine, 1234u);
@@ -10383,6 +10410,18 @@
   AlwaysBreakAfterReturnType,
   FormatStyle::RTBS_TopLevelDefinitions);
 
+  Style.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_All;
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: None", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_None);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: BeforeFunction", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_BeforeFunction);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: All", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_All);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: false", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_BeforeFunction);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: true", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_All);
+
   Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
   CHECK_PARSE("AlwaysBreakAfterDefinitionReturnType: None",
   AlwaysBreakAfterDefinitionReturnType, FormatStyle::DRTBS_None);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2171,6 +2171,8 @@
   return 2;
 return 1;
   }
+  if (Left.ClosesTemplateDeclaration)
+  return Style.PenaltyBreakTemplateDeclaration;
   if (Left.is(TT_ConditionalExpr))
 return prec::Conditional;
   prec::Level Level = Left.getPrecedence();
@@ -2641,7 +2643,7 @@
   if (Right.Previous->ClosesTemplateDeclaration &&
   Right.Previous->MatchingParen &&
   Right.Previous->MatchingParen->NestingLevel == 0 &&
-  Style.AlwaysBreakTemplateDeclarations)
+  Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_All)
 return true;
   if (Right

[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

2018-02-01 Thread Francois Ferrand via Phabricator via cfe-commits
Typz created this revision.
Typz added reviewers: krasimir, djasper, klimek.

There should be no extra indent when wrapping only the expression used
as last argument. This is consistent with the behavior when the first
(and only) argument's expression is wrapped.

  foo(a, bb +
 c);
  foo(b +
  c);

This does not affect all other cases, where the argument itself is
wrapped:

  foo(a,
  b +
  c,
  d);
  foo(b +
  c,
  d);


Repository:
  rC Clang

https://reviews.llvm.org/D42787

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3998,6 +3998,21 @@
   verifyFormat("a(aa +\n"
"  aa,\n"
"  aa);");
+  verifyFormat(
+  "a(aa +\n"
+  "  aa) {}");
+  verifyFormat(
+  "a(aa +\n"
+  "  aa,\n"
+  "  b) {}");
+  verifyFormat(
+  "a(b, aaa +\n"
+  " aaa) {}");
+  verifyFormat(
+  "a(b,\n"
+  "  aaa +\n"
+  "  aaa,\n"
+  "  c) {}");
 
   // Indent consistently independent of call expression and unary operator.
   verifyFormat("aaa(bbb(\n"
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1094,6 +1094,7 @@
   bool SkipFirstExtraIndent =
   (Previous && (Previous->opensScope() ||
 Previous->isOneOf(tok::semi, tok::kw_return) ||
+(Previous->is(tok::comma) && !Newline) ||
 (Previous->getPrecedence() == prec::Assignment &&
  Style.AlignOperands) ||
 Previous->is(TT_ObjCMethodExpr)));


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3998,6 +3998,21 @@
   verifyFormat("a(aa +\n"
"  aa,\n"
"  aa);");
+  verifyFormat(
+  "a(aa +\n"
+  "  aa) {}");
+  verifyFormat(
+  "a(aa +\n"
+  "  aa,\n"
+  "  b) {}");
+  verifyFormat(
+  "a(b, aaa +\n"
+  " aaa) {}");
+  verifyFormat(
+  "a(b,\n"
+  "  aaa +\n"
+  "  aaa,\n"
+  "  c) {}");
 
   // Indent consistently independent of call expression and unary operator.
   verifyFormat("aaa(bbb(\n"
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1094,6 +1094,7 @@
   bool SkipFirstExtraIndent =
   (Previous && (Previous->opensScope() ||
 Previous->isOneOf(tok::semi, tok::kw_return) ||
+(Previous->is(tok::comma) && !Newline) ||
 (Previous->getPrecedence() == prec::Assignment &&
  Style.AlignOperands) ||
 Previous->is(TT_ObjCMethodExpr)));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41698: [DebugInfo] Enable debug information for C99 VLA types

2018-02-01 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen marked an inline comment as done.
sdesmalen added a comment.

Thanks for your review @aprantl!


https://reviews.llvm.org/D41698



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


[PATCH] D41698: [DebugInfo] Enable debug information for C99 VLA types

2018-02-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC323952: [DebugInfo] Enable debug information for C99 VLA 
types (authored by s.desmalen, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41698?vs=132275&id=132350#toc

Repository:
  rC Clang

https://reviews.llvm.org/D41698

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/debug-info-vla.c
  test/CodeGenCXX/debug-info-vla.cpp
  test/CodeGenCXX/vla-consruct.cpp
  test/CodeGenObjC/arc.m
  test/OpenMP/target_codegen.cpp
  test/OpenMP/target_parallel_codegen.cpp
  test/OpenMP/target_parallel_for_codegen.cpp
  test/OpenMP/target_parallel_for_simd_codegen.cpp
  test/OpenMP/target_simd_codegen.cpp
  test/OpenMP/target_teams_codegen.cpp
  test/OpenMP/target_teams_distribute_codegen.cpp
  test/OpenMP/target_teams_distribute_simd_codegen.cpp

Index: test/CodeGenCXX/vla-consruct.cpp
===
--- test/CodeGenCXX/vla-consruct.cpp
+++ test/CodeGenCXX/vla-consruct.cpp
@@ -21,6 +21,8 @@
   // CHECK: define void {{.*test.*}}(i32 [[n:%.+]]) #
   // CHECK: [[n_addr:%.+]] = alloca
   // CHECK-NEXT: [[saved_stack:%.+]] = alloca
+  // CHECK-NEXT: [[vla_expr:%.+]] = alloca i64, align 8
+  // CHECK-NEXT: [[vla_expr1:%.+]] = alloca i64, align 8
   // CHECK-NEXT: [[sizeof_S:%.+]] = alloca
   // CHECK-NEXT: [[sizeof_array_t_0_0:%.+]] = alloca
   // CHECK-NEXT: [[sizeof_array_t_0:%.+]] = alloca
@@ -37,6 +39,8 @@
   // CHECK-NEXT: store i8* [[t4]], i8** [[saved_stack]]
   // CHECK-NEXT: [[t5:%.+]] = mul nuw i64 [[t1]], [[t3]]
   // CHECK-NEXT: [[vla:%.+]] = alloca [[struct_S]], i64 [[t5]]
+  // CHECK-NEXT: store i64 [[t1]], i64* [[vla_expr]]
+  // CHECK-NEXT: store i64 [[t3]], i64* [[vla_expr1]]
   // CHECK-NEXT: [[t6:%.+]] = mul nuw i64 [[t1]], [[t3]]
   // CHECK-NEXT: [[isempty:%.+]] = icmp eq i64 [[t6]], 0
   // CHECK-NEXT: br i1 [[isempty]], label %[[arrayctor_cont:.+]], label %[[new_ctorloop:.+]]
Index: test/CodeGenCXX/debug-info-vla.cpp
===
--- test/CodeGenCXX/debug-info-vla.cpp
+++ test/CodeGenCXX/debug-info-vla.cpp
@@ -13,8 +13,10 @@
 // CHECK: [[ELEM_TYPE]] = !{[[NOCOUNT:.*]]}
 // CHECK: [[NOCOUNT]] = !DISubrange(count: -1)
 //
+// CHECK: [[VAR:![0-9]+]] = !DILocalVariable(name: "vla_expr"
 // CHECK: !DICompositeType(tag: DW_TAG_array_type,
 // CHECK-NOT:   size:
 // CHECK-SAME:  elements: [[ELEM_TYPE:![0-9]+]]
-// CHECK: [[ELEM_TYPE]] = !{[[THREE:.*]], [[NOCOUNT]]}
+// CHECK: [[ELEM_TYPE]] = !{[[THREE:.*]], [[VARRANGE:![0-9]+]]}
 // CHECK: [[THREE]] = !DISubrange(count: 3)
+// CHECK: [[VARRANGE]] = !DISubrange(count: [[VAR]])
Index: test/CodeGen/debug-info-vla.c
===
--- test/CodeGen/debug-info-vla.c
+++ test/CodeGen/debug-info-vla.c
@@ -2,9 +2,11 @@
 
 void testVLAwithSize(int s)
 {
-// CHECK: dbg.declare
-// CHECK: dbg.declare({{.*}}, metadata ![[VAR:.*]], metadata !DIExpression())
-// CHECK: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+1]]
+// CHECK-DAG: dbg.declare({{.*}} %vla_expr, metadata ![[VLAEXPR:[0-9]+]]
+// CHECK-DAG: dbg.declare({{.*}} %vla, metadata ![[VAR:[0-9]+]]
+// CHECK-DAG: ![[VLAEXPR]] = !DILocalVariable(name: "vla_expr"
+// CHECK-DAG: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+2]]
+// CHECK-DAG: !DISubrange(count: ![[VLAEXPR]])
   int vla[s];
   int i;
   for (i = 0; i < s; i++) {
Index: test/CodeGenObjC/arc.m
===
--- test/CodeGenObjC/arc.m
+++ test/CodeGenObjC/arc.m
@@ -538,6 +538,7 @@
   // CHECK-LABEL: define void @test20
   // CHECK:  [[N:%.*]] = alloca i32, align 4
   // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8*
+  // CHECK-NEXT: [[VLA_EXPR:%.*]] = alloca i64, align 8
   // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4
 
   id x[n];
@@ -553,6 +554,9 @@
   // Allocate the VLA.
   // CHECK-NEXT: [[VLA:%.*]] = alloca i8*, i64 [[DIM]], align 16
 
+  // Store the VLA #elements expression.
+  // CHECK-NEXT: store i64 %1, i64* [[VLA_EXPR]], align 8
+
   // Zero-initialize.
   // CHECK-NEXT: [[T0:%.*]] = bitcast i8** [[VLA]] to i8*
   // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[DIM]], 8
@@ -579,6 +583,7 @@
   // CHECK-LABEL: define void @test21
   // CHECK:  [[N:%.*]] = alloca i32, align 4
   // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8*
+  // CHECK-NEXT: [[VLA_EXPR:%.*]] = alloca i64, align 8
   // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4
 
   id x[2][n][3];
@@ -595,6 +600,9 @@
   // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]]

[PATCH] D41698: [DebugInfo] Enable debug information for C99 VLA types

2018-02-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL323952: [DebugInfo] Enable debug information for C99 VLA 
types (authored by s.desmalen, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D41698?vs=132275&id=132351#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41698

Files:
  cfe/trunk/lib/CodeGen/CGBlocks.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.h
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGExprScalar.cpp
  cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
  cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/CodeGen/debug-info-vla.c
  cfe/trunk/test/CodeGenCXX/debug-info-vla.cpp
  cfe/trunk/test/CodeGenCXX/vla-consruct.cpp
  cfe/trunk/test/CodeGenObjC/arc.m
  cfe/trunk/test/OpenMP/target_codegen.cpp
  cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
  cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
  cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
  cfe/trunk/test/OpenMP/target_simd_codegen.cpp
  cfe/trunk/test/OpenMP/target_teams_codegen.cpp
  cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
  cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen.cpp

Index: cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
===
--- cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
+++ cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
@@ -555,6 +555,7 @@
 // CHECK-64:   store i32 %{{.+}}, i32* [[B_ADDR]],
 // CHECK-64:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_CADDR]],
 
+// CHECK-32:   store i32 %{{.+}}, i32* %vla_expr
 // CHECK-32:   store i32 %{{.+}}, i32* [[B_ADDR:%.+]],
 // CHECK-32:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_ADDR]],
 
Index: cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
===
--- cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
+++ cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
@@ -564,6 +564,7 @@
 // CHECK-64:   store i32 %{{.+}}, i32* [[B_ADDR]],
 // CHECK-64:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_CADDR]],
 
+// CHECK-32:   store i32 %{{.+}}, i32* %vla_expr
 // CHECK-32:   store i32 %{{.+}}, i32* [[B_ADDR:%.+]],
 // CHECK-32:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_ADDR]],
 
Index: cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
===
--- cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
+++ cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
@@ -528,6 +528,7 @@
 // CHECK-64:   store i32 %{{.+}}, i32* [[B_ADDR]],
 // CHECK-64:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_CADDR]],
 
+// CHECK-32:   store i32 %{{.+}}, i32* %vla_expr
 // CHECK-32:   store i32 %{{.+}}, i32* [[B_ADDR:%.+]],
 // CHECK-32:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_ADDR]],
 
Index: cfe/trunk/test/OpenMP/target_codegen.cpp
===
--- cfe/trunk/test/OpenMP/target_codegen.cpp
+++ cfe/trunk/test/OpenMP/target_codegen.cpp
@@ -511,6 +511,7 @@
 // CHECK-64:   store i32 %{{.+}}, i32* [[B_ADDR]],
 // CHECK-64:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_CADDR]],
 
+// CHECK-32:   store i32 %{{.+}}, i32* %vla_expr
 // CHECK-32:   store i32 %{{.+}}, i32* [[B_ADDR:%.+]],
 // CHECK-32:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_ADDR]],
 
Index: cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
===
--- cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
+++ cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
@@ -555,6 +555,7 @@
 // CHECK-64:   store i32 %{{.+}}, i32* [[B_ADDR]],
 // CHECK-64:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_CADDR]],
 
+// CHECK-32:   store i32 %{{.+}}, i32* %vla_expr
 // CHECK-32:   store i32 %{{.+}}, i32* [[B_ADDR:%.+]],
 // CHECK-32:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_ADDR]],
 
Index: cfe/trunk/test/OpenMP/target_teams_codegen.cpp
===
--- cfe/trunk/test/OpenMP/target_teams_codegen.cpp
+++ cfe/trunk/test/OpenMP/target_teams_codegen.cpp
@@ -553,6 +553,7 @@
 // CHECK-64:   store i32 %{{.+}}, i32* [[B_ADDR]],
 // CHECK-64:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_CADDR]],
 
+// CHECK-32:   store i32 %{{.+}}, i32* %vla_expr
 // CHECK-32:   store i32 %{{.+}}, i32* [[B_ADDR:%.+]],
 // CHECK-32:   [[B_CVAL:%.+]] = load i[[SZ]], i[[SZ]]* [[B_ADDR]],
 
Index: cfe/trunk/test/OpenMP/target_simd_codegen.cpp
==

[PATCH] D42693: [libcxx] Handle invalid escaped characters in POSIX regex

2018-02-01 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki updated this revision to Diff 132352.
miyuki edited the summary of this revision.
miyuki added a comment.

Updated __parse_QUOTED_CHAR_ERE. Added more test cases.


https://reviews.llvm.org/D42693

Files:
  include/regex
  test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp

Index: test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
===
--- test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
+++ test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
@@ -19,11 +19,13 @@
 #include 
 #include "test_macros.h"
 
-static bool error_escape_thrown(const char *pat)
+static bool error_escape_thrown(const char *pat,
+std::regex_constants::syntax_option_type
+syntax = std::regex_constants::ECMAScript)
 {
 bool result = false;
 try {
-std::regex re(pat);
+std::regex re(pat, syntax);
 } catch (const std::regex_error &ex) {
 result = (ex.code() == std::regex_constants::error_escape);
 }
@@ -45,4 +47,58 @@
 assert(!error_escape_thrown("[\\cA]"));
 assert(!error_escape_thrown("\\cA"));
 
+const std::regex_constants::syntax_option_type basic =
+std::regex_constants::basic;
+
+assert(error_escape_thrown("\\a", basic));
+assert(error_escape_thrown("\\n", basic));
+assert(error_escape_thrown("\\t", basic));
+assert(error_escape_thrown("\\0", basic));
+assert(error_escape_thrown("\\/", basic));
+assert(error_escape_thrown("\\\n", basic));
+assert(error_escape_thrown("\\", basic));
+
+assert(!error_escape_thrown("[\\a]", basic));
+assert(!error_escape_thrown("\\(a\\)", basic));
+assert(!error_escape_thrown("\\(ab\\)\\1", basic));
+assert(!error_escape_thrown("a\\{1,2\\}", basic));
+assert(!error_escape_thrown("\\.", basic));
+assert(!error_escape_thrown("\\*", basic));
+
+const std::regex_constants::syntax_option_type extended =
+std::regex_constants::extended;
+
+assert(error_escape_thrown("\\a", extended));
+assert(error_escape_thrown("\\n", extended));
+assert(error_escape_thrown("\\t", extended));
+assert(error_escape_thrown("\\0", extended));
+assert(error_escape_thrown("(ab)\\1", extended));
+assert(error_escape_thrown("\\/", extended));
+assert(error_escape_thrown("\\\n", extended));
+assert(error_escape_thrown("\\", extended));
+
+assert(!error_escape_thrown("[\\a]", extended));
+assert(!error_escape_thrown("\\(a\\)", extended));
+assert(!error_escape_thrown("\\{\\}", extended));
+assert(!error_escape_thrown("\\.", extended));
+assert(!error_escape_thrown("\\*", extended));
+
+const std::regex_constants::syntax_option_type awk =
+std::regex_constants::awk;
+
+assert(error_escape_thrown("\\z", awk));
+assert(error_escape_thrown("[\\z]", awk));
+assert(error_escape_thrown("\\9", awk));
+assert(error_escape_thrown("\\\n", awk));
+assert(error_escape_thrown("\\", awk));
+
+assert(!error_escape_thrown("\\n", awk));
+assert(!error_escape_thrown("\\t", awk));
+assert(!error_escape_thrown("\\/", awk));
+assert(!error_escape_thrown("\\(a\\)", awk));
+assert(!error_escape_thrown("\\{\\}", awk));
+assert(!error_escape_thrown("\\0", awk));
+assert(!error_escape_thrown("\\1", awk));
+assert(!error_escape_thrown("\\.", awk));
+assert(!error_escape_thrown("\\*", awk));
 }
Index: include/regex
===
--- include/regex
+++ include/regex
@@ -3442,23 +3442,32 @@
 {
 if (__first != __last)
 {
-_ForwardIterator __temp = _VSTD::next(__first);
-if (__temp != __last)
+if (*__first == '\\')
 {
-if (*__first == '\\')
+_ForwardIterator __temp = _VSTD::next(__first);
+if (__temp == __last)
+__throw_regex_error();
+
+switch (*__temp)
 {
-switch (*__temp)
-{
-case '^':
-case '.':
-case '*':
-case '[':
-case '$':
-case '\\':
-__push_char(*__temp);
-__first = ++__temp;
+case '^':
+case '.':
+case '*':
+case '[':
+case '$':
+case '\\':
+__push_char(*__temp);
+__first = ++__temp;
+break;
+case '(':
+case ')':
+case '{':
+case '}':
+break;
+default:
+if (*__temp >= '1' && *__temp <= '9')
 break;
-}
+__throw_regex_error();
 }
 }
 }
@@ -3473,34 +3482,36 @@
 {
 if (__first != __last)
 {
-_ForwardIterator __temp = _VST

[PATCH] D42693: [libcxx] Handle invalid escaped characters in POSIX regex

2018-02-01 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki added inline comments.



Comment at: include/regex:3490
 {
 switch (*__temp)
 {

mclow.lists wrote:
> Do we need any more cases here?
Probably not, but we should throw an exception here as well.


https://reviews.llvm.org/D42693



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


[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

2018-02-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

I am against this change. The current behavior here is intentional and IMO more 
consistent. If there is more than one precedence level in a set of parentheses, 
we add the additional indentation. If you don't like it, surround it with extra 
parentheses.

Generally, it'd be useful to have a "before" and "after" example in the patch 
description. That way, we can get more feedback from other people more easily.


Repository:
  rC Clang

https://reviews.llvm.org/D42787



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


[clang-tools-extra] r323957 - [clangd] Fix URI scheme conflict and an unused variable warning in tests. NFC

2018-02-01 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Feb  1 04:44:52 2018
New Revision: 323957

URL: http://llvm.org/viewvc/llvm-project?rev=323957&view=rev
Log:
[clangd] Fix URI scheme conflict and an unused variable warning in tests. NFC

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/unittests/clangd/URITests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=323957&r1=323956&r2=323957&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Feb  1 04:44:52 2018
@@ -44,7 +44,8 @@ public:
 llvm::SmallVector Path(Body.begin(), Body.end());
 path::native(Path);
 auto Err = fs::make_absolute(TestDir, Path);
-assert(!Err);
+if (Err)
+  llvm_unreachable("Failed to make absolute path in test scheme.");
 return std::string(Path.begin(), Path.end());
   }
 

Modified: clang-tools-extra/trunk/unittests/clangd/URITests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/URITests.cpp?rev=323957&r1=323956&r2=323957&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/URITests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/URITests.cpp Thu Feb  1 04:44:52 
2018
@@ -49,7 +49,7 @@ public:
   }
 };
 
-const char *TestScheme::Scheme = "test";
+const char *TestScheme::Scheme = "unittest";
 const char *TestScheme::TestRoot = "/test-root/";
 
 static URISchemeRegistry::Add X(TestScheme::Scheme, "Test schema");
@@ -166,7 +166,7 @@ TEST(URITest, Resolve) {
 #else
   EXPECT_EQ(resolveOrDie(parseOrDie("file:/a/b/c")), "/a/b/c");
   EXPECT_EQ(resolveOrDie(parseOrDie("file://auth/a/b/c")), "/a/b/c");
-  EXPECT_EQ(resolveOrDie(parseOrDie("test:a/b/c"), "/dir/test-root/x/y/z"),
+  EXPECT_EQ(resolveOrDie(parseOrDie("unittest:a/b/c"), "/dir/test-root/x/y/z"),
 "/dir/test-root/a/b/c");
   EXPECT_THAT(resolveOrDie(parseOrDie("file://au%3dth/%28x%29/y/%20z")),
   "/(x)/y/ z");


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


[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

2018-02-01 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

I doubt this particular was intentional, esp. since this case never happens in 
the tests. I think it is more a side-effect of the (general) indent in "fake" 
parenthesis.
Here is an exemple:

Before this change:

  foo(a, bb +
 c);
  foo(b +
  c);
  foo(a,
  b +
  c,
  d);
  foo(b +
  c,
  d);

After this change:

  foo(a, bb +
 c);
  foo(b +
  c);
  foo(a,
  b +
  c,
  d);
  foo(b +
  c,
  d);

i.e. this patch only affect the 'first' scenario (e.g. wrapping expression in 
last argument) consistent with the second one (e.g. wrapping expression in 
first and only argument)


Repository:
  rC Clang

https://reviews.llvm.org/D42787



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


[clang-tools-extra] r323960 - [clangd] remove the unused code NFC.

2018-02-01 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Feb  1 05:06:58 2018
New Revision: 323960

URL: http://llvm.org/viewvc/llvm-project?rev=323960&view=rev
Log:
[clangd] remove the unused code NFC.

Modified:
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=323960&r1=323959&r2=323960&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Thu Feb  
1 05:06:58 2018
@@ -53,9 +53,6 @@ MATCHER_P(LocationOffsets, Offsets, "")
   return arg.CanonicalDeclaration.StartOffset == Offsets.first &&
   arg.CanonicalDeclaration.EndOffset == Offsets.second - 1;
 }
-//MATCHER_P(FilePath, P, "") {
-  //return arg.CanonicalDeclaration.FilePath.contains(P);
-//}
 
 namespace clang {
 namespace clangd {


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


[PATCH] D42361: [Tooling] Returns non-zero status code when files are skipped.

2018-02-01 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: lib/Tooling/Tooling.cpp:404
 if (CompileCommandsForFile.empty()) {
   // FIXME: There are two use cases here: doing a fuzzy
   // "find . -name '*.cc' |xargs tool" match, where as a user I don't care

ioeric wrote:
> bkramer wrote:
> > This comment explains why the implementation doesn't error. Can you make 
> > sure the xargs use case is still working properly?
> I somehow missed the big `FIXME`... thanks for the catch! 
> 
> I don't think this is a very typical use case that should affect design 
> decision here, and I would expect `xargs` users to do something like `xargs 
> tool $@ || true` if they really want to ignore errors. WDYT?
Yeah. I think the only important thing is that xargs doesn't stop after the 
first error. But that seems to be the default behavior of xargs?


Repository:
  rC Clang

https://reviews.llvm.org/D42361



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


[PATCH] D42645: New simple Checker for mmap calls

2018-02-01 Thread David CARLIER via Phabricator via cfe-commits
devnexen added a comment.

Another example with pcre2, more specifically its JIT engine

  In file included from 
/home/dcarlier/Contribs/php-src/ext/pcre/pcre2lib/pcre2_jit_compile.c:78:
  In file included from 
/home/dcarlier/Contribs/php-src/ext/pcre/pcre2lib/sljit/sljitLir.c:261:
  
/home/dcarlier/Contribs/php-src/ext/pcre/pcre2lib/sljit/sljitExecAllocator.c:102:11:
 warning: Both PROT_WRITE and PROT_EXEC flags had been set. It can leads to 
exploitable memory regions, overwritten with malicious code
  retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, 
MAP_PRIVATE | MAP_ANON, -1, 0);
   
^~~
  In file included from 
/home/dcarlier/Contribs/php-src/ext/pcre/pcre2lib/pcre2_jit_compile.c:78:
  In file included from 
/home/dcarlier/Contribs/php-src/ext/pcre/pcre2lib/sljit/sljitLir.c:1737:


Repository:
  rC Clang

https://reviews.llvm.org/D42645



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


[PATCH] D42361: [Tooling] Returns non-zero status code when files are skipped.

2018-02-01 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: lib/Tooling/Tooling.cpp:404
 if (CompileCommandsForFile.empty()) {
   // FIXME: There are two use cases here: doing a fuzzy
   // "find . -name '*.cc' |xargs tool" match, where as a user I don't care

bkramer wrote:
> ioeric wrote:
> > bkramer wrote:
> > > This comment explains why the implementation doesn't error. Can you make 
> > > sure the xargs use case is still working properly?
> > I somehow missed the big `FIXME`... thanks for the catch! 
> > 
> > I don't think this is a very typical use case that should affect design 
> > decision here, and I would expect `xargs` users to do something like `xargs 
> > tool $@ || true` if they really want to ignore errors. WDYT?
> Yeah. I think the only important thing is that xargs doesn't stop after the 
> first error. But that seems to be the default behavior of xargs?
Looks like this is the case, from the manual:
```
If  any  invocation of the command exits with a status of 255, xargs will stop 
immediately without reading any further input.  An error message is issued on 
stderr when this happens.
```

Should I just remove the FIXME?


Repository:
  rC Clang

https://reviews.llvm.org/D42361



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


[PATCH] D34249: [libc++] Don't use UTIME_OMIT to detect utimensat on Apple

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

The powers that be updated the SDK on the chromium clang bots, so we need some 
solution for this issue soon.

The approach in this patch should work, but it seems conservative. Now libc++ 
only uses utimesat() if it's built with a deployment target of macOS 10.13. But 
if we were to set a deployment target of 10.12 and then _run_ on 10.13, we 
could use utimesat() as well, even though this patch currently doesn't. (Apple 
bundles libc++ with the system, so it's not a meaningful difference for 
Apple-built libc++'s, but applications can build libc++ themselves and 
statically link to it, and for those it would make a difference.)

https://clang.llvm.org/docs/LanguageExtensions.html#objective-c-available has 
some words on it (except that `@available` is spelled `__builtin_available` in 
non-Objective-C code) -- thoughts on using runtime detection of utimes() 
instead? That's how things are supposed to work on the Apple platforms.


https://reviews.llvm.org/D34249



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


[PATCH] D42035: [clang-format] Fixup #include guard indents after parseFile()

2018-02-01 Thread Mark Zeren via Phabricator via cfe-commits
mzeren-vmw added inline comments.



Comment at: lib/Format/UnwrappedLineParser.cpp:244
   PPBranchLevel = -1;
-  IfNdefCondition = nullptr;
-  FoundIncludeGuardStart = false;
-  IncludeGuardRejected = false;
+  IncludeGuard = IG_Inited;
+  IncludeGuardToken = nullptr;

Hm. From self review, I think this should be:

IncludeGuard = Style.IndentPPDirectives == FormatStyle::PPDIS_None ? 
IG_Rejected : IG_Inited;



Comment at: lib/Format/UnwrappedLineParser.cpp:736
   bool MaybeIncludeGuard = IfNDef;
-  if (!IncludeGuardRejected && !FoundIncludeGuardStart && MaybeIncludeGuard) {
+  if (IncludeGuard == IG_Inited && MaybeIncludeGuard) {
 for (auto &Line : Lines) {

technically I could drop the braces opened on this line. Would you like me to 
do that?


Repository:
  rC Clang

https://reviews.llvm.org/D42035



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


[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

2018-02-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

You might doubt it, but having written the code I can tell you that it's the 
case. Shame on me for not writing a test, though.

I see the argument why this indentation is not necessary in exactly the case 
where the last parameter is multi-line and not wrapped to a new line itself: 
You always have some indentation anyway because of the preceding parameter on 
the same line.
However, for me the consistency is more important here, i.e.  achieving that we 
don't have a relative indentation change between:

  foo(a, bb +
 c);

and

  foo(a,
  bb +
  c);

This formatting can easily alter between these two when line length vary 
slightly and I think being able to pattern match that easily.
Yes, that means it is not consistent with:

  foo(bb +
  c);

But there is actually a substantial difference in structure and so, I think it 
is reasonable to not be consistent there.


Repository:
  rC Clang

https://reviews.llvm.org/D42787



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


[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

2018-02-01 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

> You might doubt it, but having written the code I can tell you that it's the 
> case.

Ok, you win :-)

> I see the argument why this indentation is not necessary in exactly the case 
> where the last parameter is multi-line and not wrapped to a new line itself: 
> You always have some indentation anyway because of the preceding parameter on 
> the same line.
>  However, for me the consistency is more important here, i.e. achieving that 
> we don't have a relative indentation change between:
>  [...] 
>  This formatting can easily alter between these two when line length vary 
> slightly and I think being able to pattern match that easily.

Not sure what you mean: a diff would not be trivial in either case...

> Yes, that means it is not consistent with:
> 
>   foo(bb +
>   c);
>
> 
> But there is actually a substantial difference in structure and so, I think 
> it is reasonable to not be consistent there.

It's reasonable from the perspective of the tool [i.e. to make the code of 
clang-format consistent], but IMHO not so consistent from the perspective of a 
user:
I (and most people I believe) would not manually add this seemingly unnecessary 
indentation, so I would prefer the tool to do the same; and fortunately it 
seems pretty trivial to implement.

Is there a way this can go in anyway, for exemple with a setting?


Repository:
  rC Clang

https://reviews.llvm.org/D42787



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


[PATCH] D39571: [clangd] DidChangeConfiguration Notification

2018-02-01 Thread Simon Marchi via Phabricator via cfe-commits
simark added inline comments.



Comment at: clangd/ClangdLSPServer.cpp:302
 
+// FIXME: This function needs to be properly tested.
+void ClangdLSPServer::onChangeConfiguration(

ilya-biryukov wrote:
> simark wrote:
> > simark wrote:
> > > ilya-biryukov wrote:
> > > > simark wrote:
> > > > > ilya-biryukov wrote:
> > > > > > simark wrote:
> > > > > > > ilya-biryukov wrote:
> > > > > > > > Are you planning to to address this FIXME before checking the 
> > > > > > > > code in?
> > > > > > > Following what you said here:
> > > > > > > 
> > > > > > > https://reviews.llvm.org/D39571?id=124024#inline-359345
> > > > > > > 
> > > > > > > I have not really looked into what was wrong with the test, and 
> > > > > > > what is missing in the infrastructure to make it work.  But I 
> > > > > > > assumed that the situation did not change since then.  Can you 
> > > > > > > enlighten me on what the problem was, and what is missing?
> > > > > > We usually write unittests for that kind of thing, since they allow 
> > > > > > to plug an in-memory filesystem, but we only test `ClangdServer` 
> > > > > > (examples are in `unittests/clangd/ClangdTests.cpp`). 
> > > > > > `ClangdLSPServer` does not allow to plug in a virtual filesystem 
> > > > > > (vfs). Even if we add vfs, it's still hard to unit-test because 
> > > > > > we'll have to match the json input/output directly.
> > > > > > 
> > > > > > This leaves us with an option of a lit test that runs `clangd` 
> > > > > > directly, similar to tests in `test/clangd`.
> > > > > > The lit test would need to create a temporary directory, create 
> > > > > > proper `compile_commands.json` there, then send the LSP commands 
> > > > > > with the path to the test to clangd.
> > > > > > One major complication is that in LSP we have to specify the size 
> > > > > > of each message, but in our case the size would change depending on 
> > > > > > created temp path. It means we'll have to patch the test input to 
> > > > > > setup proper paths and message sizes.
> > > > > > If we choose to go down this path, 
> > > > > > `clang-tools-extra/test/clang-tidy/vfsoverlay.cpp` does a similar 
> > > > > > setup (create temp-dir, patch up some configuration files to point 
> > > > > > into the temp directory, etc) and could be used as a starting point.
> > > > > > 
> > > > > > It's not impossible to write that test, it's just a bit involved. 
> > > > > > Having a test would be nice, though, to ensure we don't break this 
> > > > > > method while doing other things. Especially given that this 
> > > > > > functionality is not used anywhere in clangd.
> > > > > > We usually write unittests for that kind of thing, since they allow 
> > > > > > to plug an in-memory filesystem, but we only test ClangdServer 
> > > > > > (examples are in unittests/clangd/ClangdTests.cpp). ClangdLSPServer 
> > > > > > does not allow to plug in a virtual filesystem (vfs). Even if we 
> > > > > > add vfs, it's still hard to unit-test because we'll have to match 
> > > > > > the json input/output directly.
> > > > > 
> > > > > What do you mean by "we'll have to match the json input/output 
> > > > > directly"?  That we'll have to match the complete JSON output 
> > > > > textually?  Couldn't the test parse the JSON into some data 
> > > > > structures, then we could assert specific things, like that this 
> > > > > particular field is present and contains a certain substring, for 
> > > > > example?
> > > > > 
> > > > > > This leaves us with an option of a lit test that runs clangd 
> > > > > > directly, similar to tests in test/clangd.
> > > > > > The lit test would need to create a temporary directory, create 
> > > > > > proper compile_commands.json there, then send the LSP commands with 
> > > > > > the path to the test to clangd.
> > > > > > One major complication is that in LSP we have to specify the size 
> > > > > > of each message, but in our case the size would change depending on 
> > > > > > created temp path. It means we'll have to patch the test input to 
> > > > > > setup proper paths and message sizes.
> > > > > > If we choose to go down this path, 
> > > > > > clang-tools-extra/test/clang-tidy/vfsoverlay.cpp does a similar 
> > > > > > setup (create temp-dir, patch up some configuration files to point 
> > > > > > into the temp directory, etc) and could be used as a starting point.
> > > > > 
> > > > > Ok, I see the complication with the Content-Length.  I am not 
> > > > > familiar with lit yet, so I don't know what it is capable of.  But 
> > > > > being able to craft and send arbitrary LSP messages would certainly 
> > > > > be helpful in the future for all kinds of black box test, so having a 
> > > > > framework that allows to do this would be helpful, I think.  I'm not 
> > > > > familiar enough with the ecosystem to do this right now, but I'll 
> > > > > keep it in mind.
> > > > > 
> > > > > One question about this particular test.  Would there be some race 
> > > > > 

[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

2018-02-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

I don't mean trivial with a diff. What I mean is, users will find it surprising 
if whether or not a parameter gets wrapped leads to a different indentation 
internal to that parameter. I have not heard of a single user that would be 
surprised by this extra indentation.

I don't think this is worth an extra setting. I'll be somewhat resistant to 
getting this in because a) I think it's wrong and b) never change a running 
system (users will have at least gotten used to it). But I also don't want to 
assume total power here, I do not care that much about this issue. I'll add 
some other clang-format authors as reviewers here and you can also feel free to 
add more people. If the common opinion is that your change is good, I am happy 
to move forward.


Repository:
  rC Clang

https://reviews.llvm.org/D42787



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


[PATCH] D42755: [libcxx] Fix last_write_time tests for filesystems that don't support very small times.

2018-02-01 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld requested changes to this revision.
Hahnfeld added a comment.
This revision now requires changes to proceed.

Can you please add a summary that describes which filesystem this problem can 
be seen with? I think outside people can't access rdar tickets, so I can only 
guess that it's related to APFS? Further guessing the filesystem supports 
negative timestamps in general but not `file_time_type::min()` (which probably 
is `-2 ** 63`)?

In https://reviews.llvm.org/D42755#993784, @vsapsai wrote:

> Don't like removing `new_time = file_time_type::min() + MicroSec(1);` part of 
> the `test_write_min_time` but it escapes `file_time_type::min()` check. If 
> somebody can explain the purpose of this test, I'd be glad to preserve it for 
> filesystems that support very small times.


I think the idea was to have something slightly larger than 
`file_time_type::min()` which generally makes sense for testing corner cases. 
However, there is no equivalent check for `file_time_type::max()` so I'd like 
to hear @EricWF whether we should keep it.


https://reviews.llvm.org/D42755



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


[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

2018-02-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

Ah, Manuel and Krasimir are already on this thread, maybe they can comment? I 
also added Chandler and Sam who I know care about formatting somewhat.


Repository:
  rC Clang

https://reviews.llvm.org/D42787



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


[PATCH] D42729: clang-format: Fix formatting of function body followed by semicolon

2018-02-01 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

> I don't think cases where there is only a semicolon-less macro are 
> particularly frequent/important either. You probably could even add a 
> semicolon in those cases, right? How frequent are such cases in your 
> codebase? Either way, they aren't fixed by this patch, so they aren't a good 
> reason to move forward with it.

Adding a semicolon works for indentation and behavior, but leads to compiler 
warning.
So a proper fix would require to change the macro, which can easily be tricky 
with macros containings branches or loops...

It should not happen that often, but in reality it actually happens often 
enough that I found the bug while simply testing clang-format...

> I still believe that this patch adds complexity for very little gain. And I 
> am not even sure it is correct. 
> isFunctionDeclarationName/getFunctionParameterList is just yet another 
> heuristic that might go wrong. And it might go wrong in both ways. You might 
> still miss some cases and you might start incorrectly formatting stuff as 
> functions. Fundamentally clang-format just doesn't have enough info to do 
> this correctly.

As such, it does not add such complexity I think, but indeed it is not 
completely correct: it works only in the case where no line breaks are expected 
around the body (since it is still parsed as a single UnwrappedLine). So it is 
a slight improvement, but not a complete fix.

`isFunctionDeclarationName()` is an heuristic as well, but provides better 
result and does not break the existing one (since there are actually quite a 
few tests, and none get broken by this patch :-) )

I think "overall" clang-format has enough information for this case, it is just 
not available at the right time: Unwrapping is done first, then token and 
matching parenthesis are analysed and lines anotated, and these token 
anotations are needed to improve the unwrapping behavior...
I would really want to call `isFunctionDeclarationName()` from 
`UnwrappedLineParser::calculateBraceTypes()`, but parenthesis matching, nesting 
level and operators identification are not available yet.

> ".. which can easily be overlooked". If they are overlooked, nobody cares 
> about the space either, so no harm done ;).

We want to use a formatter to ensure the code is consistent: e.g. to ensure 
things that may be overlooked by a human are actually formatted according to 
the rules.
We want people to trust the tool to do the right thing, so it is best to avoid 
as many errors as possible...


Repository:
  rC Clang

https://reviews.llvm.org/D42729



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


[libcxx] r323971 - Remove ; use instead. See https://libcxx.llvm.org/TS_deprecation.html

2018-02-01 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Feb  1 06:54:25 2018
New Revision: 323971

URL: http://llvm.org/viewvc/llvm-project?rev=323971&view=rev
Log:
Remove ; use  instead. See 
https://libcxx.llvm.org/TS_deprecation.html

Removed:
libcxx/trunk/test/libcxx/experimental/optional/
libcxx/trunk/test/std/experimental/optional/
Modified:
libcxx/trunk/include/experimental/optional
libcxx/trunk/include/module.modulemap
libcxx/trunk/src/optional.cpp
libcxx/trunk/test/libcxx/double_include.sh.cpp
libcxx/trunk/test/libcxx/min_max_macros.sh.cpp

Modified: libcxx/trunk/include/experimental/optional
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/optional?rev=323971&r1=323970&r2=323971&view=diff
==
--- libcxx/trunk/include/experimental/optional (original)
+++ libcxx/trunk/include/experimental/optional Thu Feb  1 06:54:25 2018
@@ -8,915 +8,4 @@
 //
 
//===--===//
 
-#ifndef _LIBCPP_EXPERIMENTAL_OPTIONAL
-#define _LIBCPP_EXPERIMENTAL_OPTIONAL
-
-/*
-optional synopsis
-
-// C++1y
-
-namespace std { namespace experimental { inline namespace fundamentals_v1 {
-
-// 5.3, optional for object types
-template  class optional;
-
-// 5.4, In-place construction
-struct in_place_t{};
-constexpr in_place_t in_place{};
-
-// 5.5, No-value state indicator
-struct nullopt_t{see below};
-constexpr nullopt_t nullopt(unspecified);
-
-// 5.6, Class bad_optional_access
-class bad_optional_access;
-
-// 5.7, Relational operators
-template 
-  constexpr bool operator==(const optional&, const optional&);
-template 
-  constexpr bool operator!=(const optional&, const optional&);
-template 
-  constexpr bool operator<(const optional&, const optional&);
-template 
-  constexpr bool operator>(const optional&, const optional&);
-template 
-  constexpr bool operator<=(const optional&, const optional&);
-template 
-  constexpr bool operator>=(const optional&, const optional&);
-
-// 5.8, Comparison with nullopt
-template  constexpr bool operator==(const optional&, 
nullopt_t) noexcept;
-template  constexpr bool operator==(nullopt_t, const 
optional&) noexcept;
-template  constexpr bool operator!=(const optional&, 
nullopt_t) noexcept;
-template  constexpr bool operator!=(nullopt_t, const 
optional&) noexcept;
-template  constexpr bool operator<(const optional&, nullopt_t) 
noexcept;
-template  constexpr bool operator<(nullopt_t, const optional&) 
noexcept;
-template  constexpr bool operator<=(const optional&, 
nullopt_t) noexcept;
-template  constexpr bool operator<=(nullopt_t, const 
optional&) noexcept;
-template  constexpr bool operator>(const optional&, nullopt_t) 
noexcept;
-template  constexpr bool operator>(nullopt_t, const optional&) 
noexcept;
-template  constexpr bool operator>=(const optional&, 
nullopt_t) noexcept;
-template  constexpr bool operator>=(nullopt_t, const 
optional&) noexcept;
-
-// 5.9, Comparison with T
-template  constexpr bool operator==(const optional&, const T&);
-template  constexpr bool operator==(const T&, const optional&);
-template  constexpr bool operator!=(const optional&, const T&);
-template  constexpr bool operator!=(const T&, const optional&);
-template  constexpr bool operator<(const optional&, const T&);
-template  constexpr bool operator<(const T&, const optional&);
-template  constexpr bool operator<=(const optional&, const T&);
-template  constexpr bool operator<=(const T&, const optional&);
-template  constexpr bool operator>(const optional&, const T&);
-template  constexpr bool operator>(const T&, const optional&);
-template  constexpr bool operator>=(const optional&, const T&);
-template  constexpr bool operator>=(const T&, const optional&);
-
-// 5.10, Specialized algorithms
-template  void swap(optional&, optional&) noexcept(see 
below);
-template  constexpr optional make_optional(T&&);
-
-   template 
-   class optional
-   {
-   public:
- typedef T value_type;
-
- // 5.3.1, Constructors
- constexpr optional() noexcept;
- constexpr optional(nullopt_t) noexcept;
- optional(const optional&);
- optional(optional&&) noexcept(see below);
- constexpr optional(const T&);
- constexpr optional(T&&);
- template  constexpr explicit optional(in_place_t, 
Args&&...);
- template 
-   constexpr explicit optional(in_place_t, initializer_list, 
Args&&...);
-
- // 5.3.2, Destructor
- ~optional();
-
- // 5.3.3, Assignment
- optional& operator=(nullopt_t) noexcept;
- optional& operator=(const optional&);
- optional& operator=(optional&&) noexcept(see below);
- templa

[PATCH] D42729: clang-format: Fix formatting of function body followed by semicolon

2018-02-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

- Of course you find all sorts of errors while testing clang-format on a 
large-enough codebase. That doesn't mean that users run into them much.
- We have had about 10k clang-format users internally for several years. The 
semicolon issue comes up but really rarely and if it does, people happily fix 
their code not blaming clang-format.

Unrelated, my point remains that setting BlockKind in TokenAnnotator is bad 
enough that I wouldn't want to do it for reaping this small benefit. And I 
can't see how you could easily achieve the same thing without doing that.


Repository:
  rC Clang

https://reviews.llvm.org/D42729



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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-01 Thread Robert Schneider via Phabricator via cfe-commits
robot added a comment.

In https://reviews.llvm.org/D42644#993506, @kubamracek wrote:

> Cool. Can we get a lit test as well?


This is our first patch so we're unfamiliar with the LLVM testing 
infrastructure. Could you please tell us what kind of test you'd like? An 
example would also be great.

We still have some concerns regarding the portability of this patch: we don’t 
know how to portably intercept a C++ standard library function (name mangling, 
layout of types, …). In libc++abi, there’s `__cxa_rethrow_primary_exception` 
but it is not used by libstdc++. Instead, libstdc++’s implementation calls 
either `_Unwind_RaiseException` or `_Unwind_SjLj_RaiseException` directly – so 
we’ve intercepted those two for libstdc++. We didn’t check if this helps on 
other platforms (Mac and Windows come to mind).

Additionally, it might be possible there are some other interceptor functions 
missing such as `__cxa_rethrow` (for throw; statements in catch blocks) which 
might lead to analogous false positives (especially if you don’t intercept 
`_Unwind_RaiseException` in the libc++ case).

Arnaud & Robot


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644



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


r323896 - Revert "[AMDGPU] Add ds_fadd, ds_fmin, ds_fmax builtins functions"

2018-02-01 Thread Daniil Fukalov via cfe-commits
Author: dfukalov
Date: Wed Jan 31 10:49:49 2018
New Revision: 323896

URL: http://llvm.org/viewvc/llvm-project?rev=323896&view=rev
Log:
Revert "[AMDGPU] Add ds_fadd, ds_fmin, ds_fmax builtins functions"

This reverts https://reviews.llvm.org/rL323890

This reverts commit 251524ebd8c346a936f0e74b09d609d49fbaae4a.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-vi.cl

Modified: cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def?rev=323896&r1=323895&r2=323896&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def Wed Jan 31 10:49:49 2018
@@ -93,9 +93,6 @@ BUILTIN(__builtin_amdgcn_ds_bpermute, "i
 BUILTIN(__builtin_amdgcn_readfirstlane, "ii", "nc")
 BUILTIN(__builtin_amdgcn_readlane, "iii", "nc")
 BUILTIN(__builtin_amdgcn_fmed3f, "", "nc")
-BUILTIN(__builtin_amdgcn_ds_fadd, "ff*3fiib", "n")
-BUILTIN(__builtin_amdgcn_ds_fmin, "ff*3fiib", "n")
-BUILTIN(__builtin_amdgcn_ds_fmax, "ff*3fiib", "n")
 
 
//===--===//
 // VI+ only builtins.

Modified: cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-vi.cl?rev=323896&r1=323895&r2=323896&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-vi.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-vi.cl Wed Jan 31 10:49:49 2018
@@ -89,23 +89,3 @@ void test_mov_dpp(global int* out, int s
   *out = __builtin_amdgcn_mov_dpp(src, 0, 0, 0, false);
 }
 
-// CHECK-LABEL: @test_ds_fadd
-// CHECK: call float @llvm.amdgcn.ds.fadd(float addrspace(3)* %out, float 
%src, i32 0, i32 0, i1 false)
-void test_ds_fadd(local float *out, float src)
-{
-  *out = __builtin_amdgcn_ds_fadd(out, src, 0, 0, false);
-}
-
-// CHECK-LABEL: @test_ds_fmin
-// CHECK: call float @llvm.amdgcn.ds.fmin(float addrspace(3)* %out, float 
%src, i32 0, i32 0, i1 false)
-void test_ds_fmin(local float *out, float src)
-{
-  *out = __builtin_amdgcn_ds_fmin(out, src, 0, 0, false);
-}
-
-// CHECK-LABEL: @test_ds_fmax
-// CHECK: call float @llvm.amdgcn.ds.fmax(float addrspace(3)* %out, float 
%src, i32 0, i32 0, i1 false)
-void test_ds_fmax(local float *out, float src)
-{
-  *out = __builtin_amdgcn_ds_fmax(out, src, 0, 0, false);
-}


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


r323956 - Reverting patch rL323952 due to build errors that I

2018-02-01 Thread Sander de Smalen via cfe-commits
Author: s.desmalen
Date: Thu Feb  1 04:27:13 2018
New Revision: 323956

URL: http://llvm.org/viewvc/llvm-project?rev=323956&view=rev
Log:
Reverting patch rL323952 due to build errors that I
haven't encountered in local builds.


Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGen/debug-info-vla.c
cfe/trunk/test/CodeGenCXX/debug-info-vla.cpp
cfe/trunk/test/CodeGenCXX/vla-consruct.cpp
cfe/trunk/test/CodeGenObjC/arc.m
cfe/trunk/test/OpenMP/target_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=323956&r1=323955&r2=323956&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Feb  1 04:27:13 2018
@@ -1479,8 +1479,8 @@ CodeGenFunction::GenerateBlockFunction(G
 const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
 if (capture.isConstant()) {
   auto addr = LocalDeclMap.find(variable)->second;
-  (void)DI->EmitDeclareOfAutoVariable(variable, addr.getPointer(),
-  Builder);
+  DI->EmitDeclareOfAutoVariable(variable, addr.getPointer(),
+Builder);
   continue;
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=323956&r1=323955&r2=323956&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Feb  1 04:27:13 2018
@@ -2292,14 +2292,12 @@ llvm::DIType *CGDebugInfo::CreateType(co
   llvm::DIFile *Unit) {
   llvm::DIType *ElementTy = getOrCreateType(Ty->getElementType(), Unit);
   int64_t Count = Ty->getNumElements();
+  if (Count == 0)
+// If number of elements are not known then this is an unbounded array.
+// Use Count == -1 to express such arrays.
+Count = -1;
 
-  llvm::Metadata *Subscript;
-  QualType QTy(Ty, 0);
-  auto SizeExpr = SizeExprCache.find(QTy);
-  if (SizeExpr != SizeExprCache.end())
-Subscript = DBuilder.getOrCreateSubrange(0, SizeExpr->getSecond());
-  else
-Subscript = DBuilder.getOrCreateSubrange(0, Count ? Count : -1);
+  llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(0, Count);
   llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
 
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
@@ -2356,12 +2354,8 @@ llvm::DIType *CGDebugInfo::CreateType(co
   }
 }
 
-auto SizeNode = SizeExprCache.find(EltTy);
-if (SizeNode != SizeExprCache.end())
-  Subscripts.push_back(
-  DBuilder.getOrCreateSubrange(0, SizeNode->getSecond()));
-else
-  Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
+// FIXME: Verify this is right for VLAs.
+Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
 EltTy = Ty->getElementType();
   }
 
@@ -3479,14 +3473,13 @@ llvm::DIType *CGDebugInfo::EmitTypeForVa
nullptr, Elements);
 }
 
-llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
-llvm::Value *Storage,
-llvm::Optional ArgNo,
-CGBuilderTy &Builder) {
+void CGDebugInfo::EmitDeclare(const VarDecl *VD, llvm::Value *Storage,
+  llvm::Optional ArgNo,
+  CGBuilderTy &Builder) {
   assert(DebugKind >= codegenoptions::LimitedDebugInfo);
   assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
   if (VD->hasAttr())
-return nullptr;
+return;
 
   bool Unwritten =
   VD->isImplicit() || (isa(VD->getDeclContext()) &&
@@ -3504,7 +3497,7 @@ llvm::DILocalVariable *CGDebugInfo::Emit
   // If there is no debug info for this type then do not emit debug info
   // for this 

r323952 - [DebugInfo] Enable debug information for C99 VLA types

2018-02-01 Thread Sander de Smalen via cfe-commits
Author: s.desmalen
Date: Thu Feb  1 03:25:10 2018
New Revision: 323952

URL: http://llvm.org/viewvc/llvm-project?rev=323952&view=rev
Log:
[DebugInfo] Enable debug information for C99 VLA types

Summary:
This patch enables debugging of C99 VLA types by generating more precise
LLVM Debug metadata, using the extended DISubrange 'count' field that
takes a DIVariable.

This should implement:
  Bug 30553: Debug info generated for arrays is not what GDB expects (not as 
good as GCC's)
https://bugs.llvm.org/show_bug.cgi?id=30553

Reviewers: echristo, aprantl, dexonsmith, clayborg, pcc, kristof.beyls, dblaikie

Reviewed By: aprantl

Subscribers: jholewinski, schweitz, davide, fhahn, JDevlieghere, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGen/debug-info-vla.c
cfe/trunk/test/CodeGenCXX/debug-info-vla.cpp
cfe/trunk/test/CodeGenCXX/vla-consruct.cpp
cfe/trunk/test/CodeGenObjC/arc.m
cfe/trunk/test/OpenMP/target_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=323952&r1=323951&r2=323952&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Feb  1 03:25:10 2018
@@ -1479,8 +1479,8 @@ CodeGenFunction::GenerateBlockFunction(G
 const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
 if (capture.isConstant()) {
   auto addr = LocalDeclMap.find(variable)->second;
-  DI->EmitDeclareOfAutoVariable(variable, addr.getPointer(),
-Builder);
+  (void)DI->EmitDeclareOfAutoVariable(variable, addr.getPointer(),
+  Builder);
   continue;
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=323952&r1=323951&r2=323952&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Feb  1 03:25:10 2018
@@ -2292,12 +2292,14 @@ llvm::DIType *CGDebugInfo::CreateType(co
   llvm::DIFile *Unit) {
   llvm::DIType *ElementTy = getOrCreateType(Ty->getElementType(), Unit);
   int64_t Count = Ty->getNumElements();
-  if (Count == 0)
-// If number of elements are not known then this is an unbounded array.
-// Use Count == -1 to express such arrays.
-Count = -1;
 
-  llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(0, Count);
+  llvm::Metadata *Subscript;
+  QualType QTy(Ty, 0);
+  auto SizeExpr = SizeExprCache.find(QTy);
+  if (SizeExpr != SizeExprCache.end())
+Subscript = DBuilder.getOrCreateSubrange(0, SizeExpr->getSecond());
+  else
+Subscript = DBuilder.getOrCreateSubrange(0, Count ? Count : -1);
   llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
 
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
@@ -2354,8 +2356,12 @@ llvm::DIType *CGDebugInfo::CreateType(co
   }
 }
 
-// FIXME: Verify this is right for VLAs.
-Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
+auto SizeNode = SizeExprCache.find(EltTy);
+if (SizeNode != SizeExprCache.end())
+  Subscripts.push_back(
+  DBuilder.getOrCreateSubrange(0, SizeNode->getSecond()));
+else
+  Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
 EltTy = Ty->getElementType();
   }
 
@@ -3473,13 +3479,14 @@ llvm::DIType *CGDebugInfo::EmitTypeForVa
nullptr, Elements);
 }
 
-void CGDebugInfo::EmitDeclare(const VarDecl *VD, llvm::Value *Storage,
-  llvm::Optional ArgNo,
-  CGBuilderTy &Builder) {
+llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
+llvm::Value *Storage,
+   

[PATCH] D42035: [clang-format] Fixup #include guard indents after parseFile()

2018-02-01 Thread Mark Zeren via Phabricator via cfe-commits
mzeren-vmw updated this revision to Diff 132394.
mzeren-vmw added a comment.

- Add comments to IncludeGuardState.
- Fix re-initialization of IncludeGuard in UnwrappedLineParser::reset.
- Remove unnecessary block after if.
- Rebase


Repository:
  rC Clang

https://reviews.llvm.org/D42035

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

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2547,6 +2547,20 @@
"#elif FOO\n"
"#endif",
Style);
+  // Non-identifier #define after potential include guard.
+  verifyFormat("#ifndef FOO\n"
+   "#  define 1\n"
+   "#endif\n",
+   Style);
+  // #if closes past last non-preprocessor line.
+  verifyFormat("#ifndef FOO\n"
+   "#define FOO\n"
+   "#if 1\n"
+   "int i;\n"
+   "#  define A 0\n"
+   "#endif\n"
+   "#endif\n",
+   Style);
   // FIXME: This doesn't handle the case where there's code between the
   // #ifndef and #define but all other conditions hold. This is because when
   // the #define line is parsed, UnwrappedLineParser::Lines doesn't hold the
Index: lib/Format/UnwrappedLineParser.h
===
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -248,10 +248,23 @@
   // sequence.
   std::stack PPChainBranchIndex;
 
-  // Contains the #ifndef condition for a potential include guard.
-  FormatToken *IfNdefCondition;
-  bool FoundIncludeGuardStart;
-  bool IncludeGuardRejected;
+  // Include guard search state. Used to fixup preprocessor indent levels
+  // so that include guards do not participate in indentation.
+  enum IncludeGuardState {
+IG_Inited,   // Search started, looking for #ifndef.
+IG_IfNdefed, // #ifndef found, IncludeGuardToken points to condition.
+IG_Defined,  // Matching #define found, checking other requirements.
+IG_Found,// All requirements met, need to fix indents.
+IG_Rejected, // Search failed or never started.
+  };
+
+  // Current state of include guard search.
+  IncludeGuardState IncludeGuard;
+
+  // Points to the #ifndef condition for a potential include guard. Null unless
+  // IncludeGuardState == IG_IfNdefed.
+  FormatToken *IncludeGuardToken;
+
   // Contains the first start column where the source begins. This is zero for
   // normal source code and may be nonzero when formatting a code fragment that
   // does not start at the beginning of the file.
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -234,14 +234,17 @@
   CurrentLines(&Lines), Style(Style), Keywords(Keywords),
   CommentPragmasRegex(Style.CommentPragmas), Tokens(nullptr),
   Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1),
-  IfNdefCondition(nullptr), FoundIncludeGuardStart(false),
-  IncludeGuardRejected(false), FirstStartColumn(FirstStartColumn) {}
+  IncludeGuard(Style.IndentPPDirectives == FormatStyle::PPDIS_None
+   ? IG_Rejected
+   : IG_Inited),
+  IncludeGuardToken(nullptr), FirstStartColumn(FirstStartColumn) {}
 
 void UnwrappedLineParser::reset() {
   PPBranchLevel = -1;
-  IfNdefCondition = nullptr;
-  FoundIncludeGuardStart = false;
-  IncludeGuardRejected = false;
+  IncludeGuard = Style.IndentPPDirectives == FormatStyle::PPDIS_None
+ ? IG_Rejected
+ : IG_Inited;
+  IncludeGuardToken = nullptr;
   Line.reset(new UnwrappedLine);
   CommentsBeforeNextToken.clear();
   FormatTok = nullptr;
@@ -264,6 +267,14 @@
 
 readToken();
 parseFile();
+
+// If we found an include guard then all preprocessor directives (other than
+// the guard) are over-indented by one.
+if (IncludeGuard == IG_Found)
+  for (auto &Line : Lines)
+if (Line.InPPDirective && Line.Level > 0)
+  --Line.Level;
+
 // Create line with eof token.
 pushToken(FormatTok);
 addUnwrappedLine();
@@ -724,26 +735,27 @@
   // If there's a #ifndef on the first line, and the only lines before it are
   // comments, it could be an include guard.
   bool MaybeIncludeGuard = IfNDef;
-  if (!IncludeGuardRejected && !FoundIncludeGuardStart && MaybeIncludeGuard) {
+  if (IncludeGuard == IG_Inited && MaybeIncludeGuard)
 for (auto &Line : Lines) {
   if (!Line.Tokens.front().Tok->is(tok::comment)) {
 MaybeIncludeGuard = false;
-IncludeGuardRejected = true;
+IncludeGuard = IG_Rejected;
 break;
   }
 }
-  }
   --PPBranchLevel;
   parsePPUnknown();
   ++PPBranchLevel;
-  if (!IncludeGuardRejected 

[libcxx] r323972 - Remove ; use instead. See https://libcxx.llvm.org/TS_deprecation.html

2018-02-01 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Feb  1 07:21:14 2018
New Revision: 323972

URL: http://llvm.org/viewvc/llvm-project?rev=323972&view=rev
Log:
Remove ; use  instead. See 
https://libcxx.llvm.org/TS_deprecation.html

Removed:
libcxx/trunk/test/libcxx/experimental/any/
libcxx/trunk/test/std/experimental/any/
Modified:
libcxx/trunk/include/experimental/any
libcxx/trunk/include/module.modulemap
libcxx/trunk/src/any.cpp
libcxx/trunk/test/libcxx/double_include.sh.cpp
libcxx/trunk/test/libcxx/min_max_macros.sh.cpp

Modified: libcxx/trunk/include/experimental/any
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/any?rev=323972&r1=323971&r2=323972&view=diff
==
--- libcxx/trunk/include/experimental/any (original)
+++ libcxx/trunk/include/experimental/any Thu Feb  1 07:21:14 2018
@@ -8,585 +8,4 @@
 //
 
//===--===//
 
-#ifndef _LIBCPP_EXPERIMENTAL_ANY
-#define _LIBCPP_EXPERIMENTAL_ANY
-
-/*
-   experimental/any synopsis
-
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-
-  class bad_any_cast : public bad_cast
-  {
-  public:
-virtual const char* what() const noexcept;
-  };
-
-  class any
-  {
-  public:
-
-// 6.3.1 any construct/destruct
-any() noexcept;
-
-any(const any& other);
-any(any&& other) noexcept;
-
-template 
-  any(ValueType&& value);
-
-~any();
-
-// 6.3.2 any assignments
-any& operator=(const any& rhs);
-any& operator=(any&& rhs) noexcept;
-
-template 
-  any& operator=(ValueType&& rhs);
-
-// 6.3.3 any modifiers
-void clear() noexcept;
-void swap(any& rhs) noexcept;
-
-// 6.3.4 any observers
-bool empty() const noexcept;
-const type_info& type() const noexcept;
-  };
-
-   // 6.4 Non-member functions
-  void swap(any& x, any& y) noexcept;
-
-  template
-ValueType any_cast(const any& operand);
-  template
-ValueType any_cast(any& operand);
-  template
-ValueType any_cast(any&& operand);
-
-  template
-const ValueType* any_cast(const any* operand) noexcept;
-  template
-ValueType* any_cast(any* operand) noexcept;
-
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
-*/
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS
-
-class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : 
public bad_cast
-{
-public:
-virtual const char* what() const _NOEXCEPT;
-};
-
-#if _LIBCPP_STD_VER > 11// C++ > 11
-
-_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
-_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
-void __throw_bad_any_cast()
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
-throw bad_any_cast();
-#else
-_VSTD::abort();
-#endif
-}
-
-// Forward declarations
-class any;
-
-template 
-typename add_pointer::type>::type
-_LIBCPP_INLINE_VISIBILITY
-any_cast(any const *) _NOEXCEPT;
-
-template 
-typename add_pointer<_ValueType>::type
-_LIBCPP_INLINE_VISIBILITY
-any_cast(any *) _NOEXCEPT;
-
-namespace __any_imp
-{
-  typedef typename aligned_storage<3*sizeof(void*), 
alignment_of::value>::type
-_Buffer;
-
-  template 
-  struct _IsSmallObject
-: public integral_constant::value
- % alignment_of<_Tp>::value == 0
-  && is_nothrow_move_constructible<_Tp>::value
->
-  {};
-
-  enum class _Action
-  {
-_Destroy,
-_Copy,
-_Move,
-_Get,
-_TypeInfo
-  };
-
-  template 
-  struct _SmallHandler;
-
-  template 
-  struct _LargeHandler;
-
-  template 
-  using _Handler = typename conditional<_IsSmallObject<_Tp>::value
-  , _SmallHandler<_Tp>
-  , _LargeHandler<_Tp>
->::type;
-  template 
-  using _EnableIfNotAny = typename
-enable_if<
-  !is_same::type, any>::value
->::type;
-
-} // namespace __any_imp
-
-class any
-{
-public:
-  // 6.3.1 any construct/destruct
-  _LIBCPP_INLINE_VISIBILITY
-  any() _NOEXCEPT : __h(nullptr) {}
-
-  _LIBCPP_INLINE_VISIBILITY
-  any(any const & __other) : __h(nullptr)
-  {
-if (__other.__h) __other.__call(_Action::_Copy, this);
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  any(any && __other) _NOEXCEPT : __h(nullptr)
-  {
-if (__other.__h) __other.__call(_Action::_Move, this);
-  }
-
-  template <
-  class _ValueType
-, class = __any_imp::_EnableIfNotAny<_ValueType>
->
-  _LIBCPP_INLINE_VISIBILITY
-  any(_ValueType && __value);
-
-  _LIBCPP_INLINE_VISIBILITY
-  ~any()
-  {
-this->clear();
-  }
-
-  // 6.3.2 any assignments
-  _LIBCPP_INLINE_VISIBILITY
-  any & operator=(any const & __rhs)
-  {
-any(__rhs).swap(*this);
-return *this;
-  }
-
-  _LIBCPP_INLINE_VISIBILITY
-  an

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

2018-02-01 Thread Mark Zeren via Phabricator via cfe-commits
mzeren-vmw updated this revision to Diff 132395.
mzeren-vmw added a comment.

- Reviewers: drop euhlmann, add djasper
- Rebase
- Ping


Repository:
  rC Clang

https://reviews.llvm.org/D42034

Files:
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -72,6 +72,7 @@
 
   void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
 const FormatStyle &Style = getLLVMStyle()) {
+EXPECT_EQ(Expected.str(), format(Expected, Style));
 EXPECT_EQ(Expected.str(), format(Code, Style));
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -72,6 +72,7 @@
 
   void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
 const FormatStyle &Style = getLLVMStyle()) {
+EXPECT_EQ(Expected.str(), format(Expected, Style));
 EXPECT_EQ(Expected.str(), format(Code, Style));
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r323975 - Remove ; use instead. See https://libcxx.llvm.org/TS_deprecation.html

2018-02-01 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Feb  1 07:49:27 2018
New Revision: 323975

URL: http://llvm.org/viewvc/llvm-project?rev=323975&view=rev
Log:
Remove ; use  instead. See 
https://libcxx.llvm.org/TS_deprecation.html

Removed:
libcxx/trunk/test/std/experimental/numeric/
Modified:
libcxx/trunk/include/experimental/numeric
libcxx/trunk/include/module.modulemap
libcxx/trunk/test/libcxx/double_include.sh.cpp
libcxx/trunk/test/libcxx/min_max_macros.sh.cpp

Modified: libcxx/trunk/include/experimental/numeric
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/numeric?rev=323975&r1=323974&r2=323975&view=diff
==
--- libcxx/trunk/include/experimental/numeric (original)
+++ libcxx/trunk/include/experimental/numeric Thu Feb  1 07:49:27 2018
@@ -8,112 +8,4 @@
 //
 
//===--===//
 
-#ifndef _LIBCPP_EXPERIMENTAL_NUMERIC
-#define _LIBCPP_EXPERIMENTAL_NUMERIC
-/*
-experimental/numeric synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v2 {
-
-  // 13.1.2, Greatest common divisor
-  template
-  constexpr common_type_t gcd(M m, N n);
-
-  // 13.1.3, Least common multiple
-  template
-  constexpr common_type_t lcm(M m, N n);
-
-} // namespace fundamentals_v2
-} // namespace experimental
-} // namespace std
-
- */
-
-#include 
-#include 
-#include   // is_integral
-#include// numeric_limits
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
-#if _LIBCPP_STD_VER > 11
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_V2
-
-template ::value> struct __abs;
-
-template 
-struct __abs<_Result, _Source, true> {
-_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
-_Result operator()(_Source __t) const noexcept
-{
-if (__t >= 0) return __t;
-if (__t == numeric_limits<_Source>::min()) return 
-static_cast<_Result>(__t);
-return -__t;
-}
-};
-
-template 
-struct __abs<_Result, _Source, false> {
-_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
-_Result operator()(_Source __t) const noexcept { return __t; }
-};
-
-
-template
-_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN
-inline _Tp __gcd(_Tp __m, _Tp __n)
-{
-static_assert((!is_signed<_Tp>::value), "" );
-return __n == 0 ? __m : _VSTD_LFTS_V2::__gcd<_Tp>(__n, __m % __n);
-}
-
-
-template
-_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
-common_type_t<_Tp,_Up>
-gcd(_Tp __m, _Up __n)
-{
-static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), 
"Arguments to gcd must be integer types");
-static_assert((!is_same::type, bool>::value), 
"First argument to gcd cannot be bool" );
-static_assert((!is_same::type, bool>::value), 
"Second argument to gcd cannot be bool" );
-using _Rp = common_type_t<_Tp,_Up>;
-using _Wp = make_unsigned_t<_Rp>;
-return static_cast<_Rp>(_VSTD_LFTS_V2::__gcd(
-  static_cast<_Wp>(__abs<_Rp, _Tp>()(__m)),
-  static_cast<_Wp>(__abs<_Rp, _Up>()(__n;
-}
-
-template
-_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
-common_type_t<_Tp,_Up>
-lcm(_Tp __m, _Up __n)
-{
-static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), 
"Arguments to lcm must be integer types");
-static_assert((!is_same::type, bool>::value), 
"First argument to lcm cannot be bool" );
-static_assert((!is_same::type, bool>::value), 
"Second argument to lcm cannot be bool" );
-if (__m == 0 || __n == 0)
-return 0;
-
-using _Rp = common_type_t<_Tp,_Up>;
-_Rp __val1 = __abs<_Rp, _Tp>()(__m) / _VSTD_LFTS_V2::gcd(__m, __n);
-_Rp __val2 = __abs<_Rp, _Up>()(__n);
-_LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow 
in lcm");
-return __val1 * __val2;
-}
-
-_LIBCPP_END_NAMESPACE_LFTS_V2
-
-#endif /* _LIBCPP_STD_VER > 11 */
-
-_LIBCPP_POP_MACROS
-
-#endif /* _LIBCPP_EXPERIMENTAL_NUMERIC */
+#error " has been removed. Use  instead."

Modified: libcxx/trunk/include/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/module.modulemap?rev=323975&r1=323974&r2=323975&view=diff
==
--- libcxx/trunk/include/module.modulemap (original)
+++ libcxx/trunk/include/module.modulemap Thu Feb  1 07:49:27 2018
@@ -538,10 +538,6 @@ module std [system] {
   header "experimental/memory_resource"
   export *
 }
-module numeric {
-  header "experimental/numeric"
-  export *
-}
 module propagate_const {
   header "experimental/propagate_const"
   export *

Modified: libcxx/trunk/test/libcxx/double_include.sh.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/double_include.sh.cpp?rev=323975&r1=323974&r2=323975&view=diff
==
--- libcxx/trunk/test/libcxx/

[PATCH] D42796: [clangd] Skip inline namespace when collecting scopes for index symbols.

2018-02-01 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added reviewers: sammccall, hokein.
Herald added subscribers: cfe-commits, jkorous-apple, ilya-biryukov, klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42796

Files:
  clangd/index/SymbolCollector.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -201,8 +201,7 @@
   runSymbolCollector(Header, /*Main=*/"");
   EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Red"), QName("Color"),
 QName("Green"), QName("Color2"),
-QName("ns"),
-QName("ns::Black")));
+QName("ns"), QName("ns::Black")));
 }
 
 TEST_F(SymbolCollectorTest, IgnoreNamelessSymbols) {
@@ -324,6 +323,41 @@
   EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo")));
 }
 
+TEST_F(SymbolCollectorTest, Scopes) {
+  const std::string Header = R"(
+namespace na {
+class Foo {};
+namespace nb {
+class Bar {};
+}
+}
+  )";
+  runSymbolCollector(Header, /*Main=*/"");
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAre(QName("na"), QName("na::nb"),
+   QName("na::Foo"), QName("na::nb::Bar")));
+}
+
+TEST_F(SymbolCollectorTest, SkipInlineNamespace) {
+  const std::string Header = R"(
+namespace na {
+inline namespace nb {
+class Foo {};
+}
+}
+namespace na {
+// This is still inlined.
+namespace nb {
+class Bar {};
+}
+}
+  )";
+  runSymbolCollector(Header, /*Main=*/"");
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAre(QName("na"), QName("na::nb"),
+   QName("na::Foo"), QName("na::Bar")));
+}
+
 TEST_F(SymbolCollectorTest, SymbolWithDocumentation) {
   const std::string Header = R"(
 namespace nx {
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -9,6 +9,7 @@
 
 #include "SymbolCollector.h"
 #include "../CodeCompletionStrings.h"
+#include "Logger.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/SourceManager.h"
@@ -63,14 +64,33 @@
   return AbsolutePath.str();
 }
 
-// "a::b::c", return {"a::b::", "c"}. Scope is empty if there's no qualifier.
-std::pair
-splitQualifiedName(llvm::StringRef QName) {
-  assert(!QName.startswith("::") && "Qualified names should not start with ::");
-  size_t Pos = QName.rfind("::");
-  if (Pos == llvm::StringRef::npos)
-return {StringRef(), QName};
-  return {QName.substr(0, Pos + 2), QName.substr(Pos + 2)};
+// For a symbol "a::b::c", return "a::b::". Scope is empty if there's no
+// qualifier. Inline namespaces and unscoped enums are skipped.
+llvm::Expected getScope(const NamedDecl *ND) {
+  llvm::SmallVector Contexts;
+  for (const auto *Context = ND->getDeclContext(); Context;
+   Context = Context->getParent()) {
+if (llvm::isa(Context) ||
+llvm::isa(Context))
+  break;
+
+if (const auto *NSD = dyn_cast(Context)) {
+  if (!NSD->isInlineNamespace())
+Contexts.push_back(NSD->getName());
+} else if (const auto *ED = dyn_cast(Context)) {
+  if (ED->isScoped())
+Contexts.push_back(ED->getName());
+} else {
+  return llvm::make_error(
+  llvm::Twine("Unexpected context type ") + Context->getDeclKindName() +
+  " for symbol " + ND->getQualifiedNameAsString(),
+  llvm::inconvertibleErrorCode());
+}
+  }
+  std::string Scope = llvm::join(Contexts.rbegin(), Contexts.rend(), "::");
+  if (!Scope.empty())
+Scope.append("::");
+  return Scope;
 }
 
 bool shouldFilterDecl(const NamedDecl *ND, ASTContext *ASTCtx,
@@ -172,19 +192,27 @@
 if (shouldFilterDecl(ND, ASTCtx, Opts))
   return true;
 llvm::SmallString<128> USR;
+if (ND->getIdentifier() == nullptr)
+  return true;
 if (index::generateUSRForDecl(ND, USR))
   return true;
 
 auto ID = SymbolID(USR);
 if (Symbols.find(ID) != nullptr)
   return true;
 
 auto &SM = ND->getASTContext().getSourceManager();
-std::string QName = ND->getQualifiedNameAsString();
+auto Scope = getScope(ND);
+if (!Scope) {
+  log(llvm::toString(Scope.takeError()));
+  return true;
+}
+std::string Name = ND->getName();
 
 Symbol S;
 S.ID = std::move(ID);
-std::tie(S.Scope, S.Name) = splitQualifiedName(QName);
+S.Scope = *Scope;
+S.Name = Name;
 S.SymInfo = index::getSymbolInfo(D);
 std::string FilePath;
 S.CanonicalDeclaration = GetSymbolLocation(ND, SM, Opts.FallbackDir, FilePath);
___

[PATCH] D42742: [clangd] Use pthread instead of thread_local to support more runtimes.

2018-02-01 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

Is there some way to figure out what's going on in 
clang-x86_64-linux-selfhost-modules?

I believe there should be no linux builders which are missing this function -- 
it was added to libgcc in 4.8, and we don't support older versions, so I think 
missing this function on a linux build must be a misconfiguration of some sort.


Repository:
  rL LLVM

https://reviews.llvm.org/D42742



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


[PATCH] D42800: Let CUDA toolchain support amdgpu target

2018-02-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: gregrodgers, jlebar, b-sumner, t-tye, arsenm.
Herald added subscribers: tpr, dstuttard, nhaehnle, wdng, kzhuravl, jholewinski.

Currently CUDA toolchain only supports nvptx.

This patch will let CUDA toolchain support amdgpu target. It can also serve as 
an example for supporting CUDA on other targets.

Patch by Greg Rodgers.
Lit test added by Yaxun Liu.


https://reviews.llvm.org/D42800

Files:
  include/clang/Basic/Cuda.h
  include/clang/Driver/ToolChain.h
  lib/Basic/Cuda.cpp
  lib/Basic/Targets/AMDGPU.cpp
  lib/Basic/Targets/AMDGPU.h
  lib/Basic/Targets/NVPTX.cpp
  lib/Driver/Driver.cpp
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/Cuda.cpp
  lib/Driver/ToolChains/Cuda.h
  test/Driver/cuda-phases.cu

Index: test/Driver/cuda-phases.cu
===
--- test/Driver/cuda-phases.cu
+++ test/Driver/cuda-phases.cu
@@ -7,22 +7,25 @@
 // REQUIRES: clang-driver
 // REQUIRES: powerpc-registered-target
 // REQUIRES: nvptx-registered-target
-
+// REQUIRES: amdgpu-registered-target
 //
 // Test single gpu architecture with complete compilation.
 //
 // RUN: %clang -target powerpc64le-ibm-linux-gnu -ccc-print-phases --cuda-gpu-arch=sm_30 %s 2>&1 \
-// RUN: | FileCheck -check-prefix=BIN %s
+// RUN: | FileCheck -check-prefixes=BIN,BIN_NV %s
+// RUN: %clang -target powerpc64le-ibm-linux-gnu -ccc-print-phases --cuda-gpu-arch=gfx803 %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=BIN,BIN_AMD %s
 // BIN-DAG: [[P0:[0-9]+]]: input, "{{.*}}cuda-phases.cu", cuda, (host-cuda)
 // BIN-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, cuda-cpp-output, (host-cuda)
 // BIN-DAG: [[P2:[0-9]+]]: compiler, {[[P1]]}, ir, (host-cuda)
-// BIN-DAG: [[P3:[0-9]+]]: input, "{{.*}}cuda-phases.cu", cuda, (device-cuda, sm_30)
-// BIN-DAG: [[P4:[0-9]+]]: preprocessor, {[[P3]]}, cuda-cpp-output, (device-cuda, sm_30)
-// BIN-DAG: [[P5:[0-9]+]]: compiler, {[[P4]]}, ir, (device-cuda, sm_30)
-// BIN-DAG: [[P6:[0-9]+]]: backend, {[[P5]]}, assembler, (device-cuda, sm_30)
-// BIN-DAG: [[P7:[0-9]+]]: assembler, {[[P6]]}, object, (device-cuda, sm_30)
-// BIN-DAG: [[P8:[0-9]+]]: offload, "device-cuda (nvptx64-nvidia-cuda:sm_30)" {[[P7]]}, object
-// BIN-DAG: [[P9:[0-9]+]]: offload, "device-cuda (nvptx64-nvidia-cuda:sm_30)" {[[P6]]}, assembler
+// BIN_NV-DAG: [[P3:[0-9]+]]: input, "{{.*}}cuda-phases.cu", cuda, (device-cuda, [[ARCH:sm_30]])
+// BIN_AMD-DAG: [[P3:[0-9]+]]: input, "{{.*}}cuda-phases.cu", cuda, (device-cuda, [[ARCH:gfx803]])
+// BIN-DAG: [[P4:[0-9]+]]: preprocessor, {[[P3]]}, cuda-cpp-output, (device-cuda, [[ARCH]])
+// BIN-DAG: [[P5:[0-9]+]]: compiler, {[[P4]]}, ir, (device-cuda, [[ARCH]])
+// BIN-DAG: [[P6:[0-9]+]]: backend, {[[P5]]}, assembler, (device-cuda, [[ARCH]])
+// BIN-DAG: [[P7:[0-9]+]]: assembler, {[[P6]]}, object, (device-cuda, [[ARCH]])
+// BIN-DAG: [[P8:[0-9]+]]: offload, "device-cuda (nvptx64-nvidia-cuda:[[ARCH]])" {[[P7]]}, object
+// BIN-DAG: [[P9:[0-9]+]]: offload, "device-cuda (nvptx64-nvidia-cuda:[[ARCH]])" {[[P6]]}, assembler
 // BIN-DAG: [[P10:[0-9]+]]: linker, {[[P8]], [[P9]]}, cuda-fatbin, (device-cuda)
 // BIN-DAG: [[P11:[0-9]+]]: offload, "host-cuda (powerpc64le-ibm-linux-gnu)" {[[P2]]}, "device-cuda (nvptx64-nvidia-cuda)" {[[P10]]}, ir
 // BIN-DAG: [[P12:[0-9]+]]: backend, {[[P11]]}, assembler, (host-cuda)
@@ -34,11 +37,13 @@
 //
 // RUN: %clang -target powerpc64le-ibm-linux-gnu -ccc-print-phases --cuda-gpu-arch=sm_30 %s -S 2>&1 \
 // RUN: | FileCheck -check-prefix=ASM %s
-// ASM-DAG: [[P0:[0-9]+]]: input, "{{.*}}cuda-phases.cu", cuda, (device-cuda, sm_30)
-// ASM-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, cuda-cpp-output, (device-cuda, sm_30)
-// ASM-DAG: [[P2:[0-9]+]]: compiler, {[[P1]]}, ir, (device-cuda, sm_30)
-// ASM-DAG: [[P3:[0-9]+]]: backend, {[[P2]]}, assembler, (device-cuda, sm_30)
-// ASM-DAG: [[P4:[0-9]+]]: offload, "device-cuda (nvptx64-nvidia-cuda:sm_30)" {[[P3]]}, assembler
+// RUN: %clang -target powerpc64le-ibm-linux-gnu -ccc-print-phases --cuda-gpu-arch=gfx803 %s -S 2>&1 \
+// RUN: | FileCheck -check-prefix=ASM %s
+// ASM-DAG: [[P0:[0-9]+]]: input, "{{.*}}cuda-phases.cu", cuda, (device-cuda, [[ARCH:sm_30|gfx803]])
+// ASM-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, cuda-cpp-output, (device-cuda, [[ARCH]])
+// ASM-DAG: [[P2:[0-9]+]]: compiler, {[[P1]]}, ir, (device-cuda, [[ARCH]])
+// ASM-DAG: [[P3:[0-9]+]]: backend, {[[P2]]}, assembler, (device-cuda, [[ARCH]])
+// ASM-DAG: [[P4:[0-9]+]]: offload, "device-cuda (nvptx64-nvidia-cuda:[[ARCH]])" {[[P3]]}, assembler
 // ASM-DAG: [[P5:[0-9]+]]: input, "{{.*}}cuda-phases.cu", cuda, (host-cuda)
 // ASM-DAG: [[P6:[0-9]+]]: preprocessor, {[[P5]]}, cuda-cpp-output, (host-cuda)
 // ASM-DAG: [[P7:[0-9]+]]: compiler, {[[P6]]}, ir, (host-cuda)
@@ -49,23 +54,25 @@
 //
 // RUN: %clang -target powerpc64le-ibm-linux-gnu -ccc-print-phases --cuda-gpu-arch=sm_30 --cuda-gpu-arch=sm_35 %s 2>&1 \
 // RUN:

[libcxx] r323979 - Remove std::experimental::sample; use std::sample instead. See https://libcxx.llvm.org/TS_deprecation.html

2018-02-01 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Feb  1 08:36:08 2018
New Revision: 323979

URL: http://llvm.org/viewvc/llvm-project?rev=323979&view=rev
Log:
Remove std::experimental::sample; use std::sample instead. See 
https://libcxx.llvm.org/TS_deprecation.html

Removed:
libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/
Modified:
libcxx/trunk/include/experimental/algorithm

Modified: libcxx/trunk/include/experimental/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/algorithm?rev=323979&r1=323978&r2=323979&view=diff
==
--- libcxx/trunk/include/experimental/algorithm (original)
+++ libcxx/trunk/include/experimental/algorithm Thu Feb  1 08:36:08 2018
@@ -23,11 +23,8 @@ inline namespace fundamentals_v1 {
 template 
 ForwardIterator search(ForwardIterator first, ForwardIterator last,
const Searcher &searcher);
-template 
-SampleIterator sample(PopulationIterator first, PopulationIterator last,
-  SampleIterator out, Distance n,
-  UniformRandomNumberGenerator &&g);
+
+// sample removed because it's now part of C++17
 
 } // namespace fundamentals_v1
 } // namespace experimental
@@ -56,16 +53,6 @@ _LIBCPP_INLINE_VISIBILITY
 _ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const 
_Searcher &__s)
 { return __s(__f, __l).first; }
 
-
-template 
-inline _LIBCPP_INLINE_VISIBILITY
-_SampleIterator sample(_PopulationIterator __first, _PopulationIterator __last,
-   _SampleIterator __output_iter, _Distance __n,
-   _UniformRandomNumberGenerator &&__g) {
-  return _VSTD::__sample(__first, __last, __output_iter, __n, __g);
-}
-
 _LIBCPP_END_NAMESPACE_LFTS
 
 _LIBCPP_POP_MACROS


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


[PATCH] D42704: [clang-format] Do not break Objective-C string literals inside array literals

2018-02-01 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

Ping! Any comments?


Repository:
  rC Clang

https://reviews.llvm.org/D42704



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


[PATCH] D42796: [clangd] Skip inline namespace when collecting scopes for index symbols.

2018-02-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clangd/index/SymbolCollector.cpp:69
+// qualifier. Inline namespaces and unscoped enums are skipped.
+llvm::Expected getScope(const NamedDecl *ND) {
+  llvm::SmallVector Contexts;

There is a `SuppressUnwrittenScope` option in `PrintingPolicy`,  I think we can 
probably use `printQualifiedName` with our customized policy (setting 
`SuppressUnwrittenScope` to true) here.



Comment at: clangd/index/SymbolCollector.cpp:195
 llvm::SmallString<128> USR;
+if (ND->getIdentifier() == nullptr)
+  return true;

Consider moving to `shouldFilterDecl`? We also have a check `if 
(ND->getDeclName().isEmpty())` there, which I assume does similar thing. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42796



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


[clang-tools-extra] r323980 - [clang-tidy] misc-redundant-expression: fix a crash under ubsan

2018-02-01 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Feb  1 08:39:12 2018
New Revision: 323980

URL: http://llvm.org/viewvc/llvm-project?rev=323980&view=rev
Log:
[clang-tidy] misc-redundant-expression: fix a crash under ubsan

Modified:
clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp?rev=323980&r1=323979&r2=323980&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp Thu 
Feb  1 08:39:12 2018
@@ -22,7 +22,6 @@
 #include "llvm/Support/Casting.h"
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -967,6 +966,13 @@ void RedundantExpressionCheck::checkRela
   }
 }
 
+unsigned intLog2(uint64_t X) {
+  unsigned Result = 0;
+  while (X >>= 1)
+++Result;
+  return Result;
+}
+
 void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
   if (const auto *BinOp = Result.Nodes.getNodeAs("binary")) {
 // If the expression's constants are macros, check whether they are
@@ -1043,11 +1049,11 @@ void RedundantExpressionCheck::check(con
 // If ShiftingConst is shifted left with more bits than the position of the
 // leftmost 1 in the bit representation of AndValue, AndConstant is
 // ineffective.
-if (floor(log2(AndValue.getExtValue())) >= ShiftingValue)
+if (intLog2(AndValue.getExtValue()) >= ShiftingValue)
   return;
 
 auto Diag = diag(BinaryAndExpr->getOperatorLoc(),
- "ineffective bitwise and operation.");
+ "ineffective bitwise and operation");
   }
 
   // Check for the following bound expressions:

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp?rev=323980&r1=323979&r2=323980&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp Thu 
Feb  1 08:39:12 2018
@@ -674,7 +674,7 @@ int operatorConfusion(int X, int Y, long
 {
   // Ineffective & expressions.
   Y = (Y << 8) & 0xff;
-  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: ineffective bitwise and 
operation.
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: ineffective bitwise and 
operation
   Y = (Y << 12) & 0xfff;
   // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: ineffective bitwise and
   Y = (Y << 12) & 0xff;
@@ -686,7 +686,7 @@ int operatorConfusion(int X, int Y, long
 
   // Tests for unmatched types
   Z = (Z << 8) & 0xff;
-  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: ineffective bitwise and 
operation.
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: ineffective bitwise and 
operation
   Y = (Y << 12) & 0xfffL;
   // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: ineffective bitwise and
   Z = (Y << 12) & 0xffLL;
@@ -694,6 +694,11 @@ int operatorConfusion(int X, int Y, long
   Y = (Z << 8L) & 0x77L;
   // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: ineffective bitwise and
 
+  Y = (Y << 8) & 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: ineffective bitwise and
+
+  Y = (Y << 8) & -1;
+
   // Effective expressions. Do not check.
   Y = (Y << 4) & 0x15;
   Y = (Y << 3) & 0x250;


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


Re: [PATCH] D34249: [libc++] Don't use UTIME_OMIT to detect utimensat on Apple

2018-02-01 Thread Duncan P. N. Exon Smith via cfe-commits
Using runtime availability checking doesn't make sense for a system Libc++, as 
you point out.  If we add runtime checks they ought to be non-default, and 
hidden behind configuration flags.

Also, do I remember correctly that __builtin_available requires linking against 
Foundation (and thus the Obj-C runtime) for NSProcessInfo, or has that 
dependency been removed/avoided?  It would be surprising for the C++ standard 
library to pull in the Objective-C runtime.  A reasonable configuration option, 
but not a reasonable default behaviour IMO.

> On Feb 1, 2018, at 05:52, Nico Weber via Phabricator 
>  wrote:
> 
> thakis added a comment.
> 
> The powers that be updated the SDK on the chromium clang bots, so we need 
> some solution for this issue soon.
> 
> The approach in this patch should work, but it seems conservative. Now libc++ 
> only uses utimesat() if it's built with a deployment target of macOS 10.13. 
> But if we were to set a deployment target of 10.12 and then _run_ on 10.13, 
> we could use utimesat() as well, even though this patch currently doesn't. 
> (Apple bundles libc++ with the system, so it's not a meaningful difference 
> for Apple-built libc++'s, but applications can build libc++ themselves and 
> statically link to it, and for those it would make a difference.)
> 
> https://clang.llvm.org/docs/LanguageExtensions.html#objective-c-available has 
> some words on it (except that `@available` is spelled `__builtin_available` 
> in non-Objective-C code) -- thoughts on using runtime detection of utimes() 
> instead? That's how things are supposed to work on the Apple platforms.
> 
> 
> https://reviews.llvm.org/D34249
> 
> 
> 

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


[PATCH] D42800: Let CUDA toolchain support amdgpu target

2018-02-01 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

Only commenting on parts that I'm a bit familiar with. In general, does it make 
sense to split this patch, are there different "stages" of support? Like 1) 
being able to compile an empty file, 2) generate optimized code, 3) allow using 
math functions?




Comment at: lib/Driver/ToolChains/Cuda.cpp:403-415
+  // If Verbose, save input for llc in /tmp and print all symbols
+  if (Args.hasArg(options::OPT_v)) {
+ArgStringList nmArgs;
+nmArgs.push_back(ResultingBitcodeF);
+nmArgs.push_back("-debug-syms");
+const char *nmExec = Args.MakeArgString(C.getDriver().Dir + "/llvm-nm");
+C.addCommand(llvm::make_unique(JA, *this, nmExec, nmArgs, 
Inputs));

This never gets cleaned up!



Comment at: lib/Driver/ToolChains/Cuda.cpp:531-534
+  SmallString<256> OutputFileName(Output.getFilename());
+  if (JA.isOffloading(Action::OFK_OpenMP))
+llvm::sys::path::replace_extension(OutputFileName, "cubin");
+  CmdArgs.push_back(Args.MakeArgString(OutputFileName));

That is already done in `TC.getInputFilename(Output)` (since rC318763), the 
same function call that you are removing here...



Comment at: lib/Driver/ToolChains/Cuda.cpp:639-640
+CmdArgs2.push_back(Args.MakeArgString(Output.getFilename()));
+const char *Exec2 =
+Args.MakeArgString(C.getDriver().Dir + "/clang-fixup-fatbin");
+C.addCommand(

`clang-fixup-fatbin` is not upstreamed and won't work. Sounds like a horrible 
name btw...



Comment at: lib/Driver/ToolChains/Cuda.cpp:788-793
+  // Do not add -link-cuda-bitcode or ptx42 features if gfx
+  for (Arg *A : DriverArgs)
+if (A->getOption().matches(options::OPT_cuda_gpu_arch_EQ) &&
+StringRef(A->getValue()).startswith("gfx"))
+  return;
+

You should use `GpuArch` which comes from `DriverArgs.getLastArgValue`: The 
last `-march` overrides previous arguments.


https://reviews.llvm.org/D42800



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


[PATCH] D42796: [clangd] Skip inline namespace when collecting scopes for index symbols.

2018-02-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Nice catch, and nice fix! Might be worth adding a motivating example to the 
patch description.




Comment at: clangd/index/SymbolCollector.cpp:68
+// For a symbol "a::b::c", return "a::b::". Scope is empty if there's no
+// qualifier. Inline namespaces and unscoped enums are skipped.
+llvm::Expected getScope(const NamedDecl *ND) {

I'd expand on this for inline namespaces a little, because it's non-obvious. 
e.g.

  // Inline namespaces are treated as transparent scopes.
  // This reflects the way they're most commonly used for lookup.
  // Ideally we'd include them, but at query time it's hard to find all the 
inline
  // namespaces to query: the preamble doesn't have a dedicated list.

Conversely, I don't think you need to explicitly mention unscoped enums 
anymore, because the behavior for transparent scopes is the obvious one, and we 
shouldn't need any special code handling enums (see below suggestions).



Comment at: clangd/index/SymbolCollector.cpp:71
+  llvm::SmallVector Contexts;
+  for (const auto *Context = ND->getDeclContext(); Context;
+   Context = Context->getParent()) {

if the condition is `!Context->isTranslationUnit()` you can skip the break 
inside, which I think reads more naturally. You'll never reach null - only TU 
can have a null parent I think.



Comment at: clangd/index/SymbolCollector.cpp:71
+  llvm::SmallVector Contexts;
+  for (const auto *Context = ND->getDeclContext(); Context;
+   Context = Context->getParent()) {

sammccall wrote:
> if the condition is `!Context->isTranslationUnit()` you can skip the break 
> inside, which I think reads more naturally. You'll never reach null - only TU 
> can have a null parent I think.
uber-nit: I think `DC` is pretty common in clang to refer to a DeclContext - 
once I got used to it, it seems less ambiguous than Context. Up to you though.



Comment at: clangd/index/SymbolCollector.cpp:73
+   Context = Context->getParent()) {
+if (llvm::isa(Context) ||
+llvm::isa(Context))

I'm not sure this is always correct: at least clang accepts this code:

  namespace X { extern "C++" { int y; }}

and you'll emit "y" instead of "X::y".

I think the check you want is

  if (Context->isTransparentContext() || Context->isInlineNamespace())
continue;

 isTransparentContext will handle the Namespace and Enum cases as you do below, 
including the enum/enum class distinction.

(The code you have below is otherwise correct, I think - but a reader needs to 
think about more separate cases in order to see that)



Comment at: clangd/index/SymbolCollector.cpp:76
+  break;
+
+if (const auto *NSD = dyn_cast(Context)) {

With the changes suggested above, I think we only get to this point in these 
cases:
 1. non-inline namespace
 2. decl is in some other named scope (class, scoped enum, ...)

Currently case 2 is symbols we're not indexing: shouldFilterDecl() should be 
false. So this is a programming error. So I think we just want

  Contexts.push_back(cast(Context)->getName());

which includes an assertion. Returning Expected seems weird here - we should 
never hit it unless a precondition is violated.



Comment at: clangd/index/SymbolCollector.cpp:90
+  }
+  std::string Scope = llvm::join(Contexts.rbegin(), Contexts.rend(), "::");
+  if (!Scope.empty())

(nit: might be slightly more obvious just to write the for loop and avoid the 
special case, up to you)



Comment at: clangd/index/SymbolCollector.cpp:113
   // violations.
   if (ND->isInAnonymousNamespace())
 return true;

Hmm, if this is ever hot-path, we may want to eventually combine "determine 
scope" and "shouldFilter" somewhat. shouldFilterDecl is doing much the same 
upwards-scope-traversal, and it seems pretty redundant.

Nothing to do for now though.



Comment at: clangd/index/SymbolCollector.cpp:195
 llvm::SmallString<128> USR;
+if (ND->getIdentifier() == nullptr)
+  return true;

hokein wrote:
> Consider moving to `shouldFilterDecl`? We also have a check `if 
> (ND->getDeclName().isEmpty())` there, which I assume does similar thing. 
hmm, what case is this handling? should `shouldFilterDecl` catch it?



Comment at: unittests/clangd/SymbolCollectorTests.cpp:326
 
+TEST_F(SymbolCollectorTest, Scopes) {
+  const std::string Header = R"(

you could consider modifying one of the testcases to have a weird 
linkage-spec-inside-namespace thing I mentioned :-)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42796



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

Re: [PATCH] D34249: [libc++] Don't use UTIME_OMIT to detect utimensat on Apple

2018-02-01 Thread Nico Weber via cfe-commits
(To be clear, the patch as-is is 100% fine with me.)

On Thu, Feb 1, 2018 at 11:44 AM, Duncan P. N. Exon Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Using runtime availability checking doesn't make sense for a system
> Libc++, as you point out.  If we add runtime checks they ought to be
> non-default, and hidden behind configuration flags.
>
> Also, do I remember correctly that __builtin_available requires linking
> against Foundation (and thus the Obj-C runtime) for NSProcessInfo, or has
> that dependency been removed/avoided?  It would be surprising for the C++
> standard library to pull in the Objective-C runtime.  A reasonable
> configuration option, but not a reasonable default behaviour IMO.
>
> > On Feb 1, 2018, at 05:52, Nico Weber via Phabricator <
> revi...@reviews.llvm.org> wrote:
> >
> > thakis added a comment.
> >
> > The powers that be updated the SDK on the chromium clang bots, so we
> need some solution for this issue soon.
> >
> > The approach in this patch should work, but it seems conservative. Now
> libc++ only uses utimesat() if it's built with a deployment target of macOS
> 10.13. But if we were to set a deployment target of 10.12 and then _run_ on
> 10.13, we could use utimesat() as well, even though this patch currently
> doesn't. (Apple bundles libc++ with the system, so it's not a meaningful
> difference for Apple-built libc++'s, but applications can build libc++
> themselves and statically link to it, and for those it would make a
> difference.)
> >
> > https://clang.llvm.org/docs/LanguageExtensions.html#
> objective-c-available has some words on it (except that `@available` is
> spelled `__builtin_available` in non-Objective-C code) -- thoughts on using
> runtime detection of utimes() instead? That's how things are supposed to
> work on the Apple platforms.
> >
> >
> > https://reviews.llvm.org/D34249
> >
> >
> >
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42803: [clangd] Log dropped diagnostics.

2018-02-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: hokein, ioeric, sammccall.
Herald added subscribers: jkorous-apple, klimek.

clangd drops diagnostics coming outside the main file, but it is still
useful to see that something went wrong in the logs.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42803

Files:
  clangd/ClangdUnit.cpp


Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -178,15 +178,18 @@
 llvm::Optional toClangdDiag(const clang::Diagnostic &D,
 DiagnosticsEngine::Level Level,
 const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-  !D.getSourceManager().isInMainFile(D.getLocation()))
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+log("Ignored diagnostic outside main file: " + Twine(Message));
 return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
 Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));


Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -178,15 +178,18 @@
 llvm::Optional toClangdDiag(const clang::Diagnostic &D,
 DiagnosticsEngine::Level Level,
 const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-  !D.getSourceManager().isInMainFile(D.getLocation()))
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+log("Ignored diagnostic outside main file: " + Twine(Message));
 return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
 Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42796: [clangd] Skip inline namespace when collecting scopes for index symbols.

2018-02-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall requested changes to this revision.
sammccall added a comment.
This revision now requires changes to proceed.

Doh, nevermind - SuppressUnwrittenScopes is way simpler. Thanks @hokein for 
catching!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42796



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


[PATCH] D16403: Add scope information to CFG

2018-02-01 Thread Maxim Ostapenko via Phabricator via cfe-commits
m.ostapenko updated this revision to Diff 132393.
m.ostapenko added a comment.

Fix scope ends order (as discussed above) and adjust a testcase.


Repository:
  rL LLVM

https://reviews.llvm.org/D16403

Files:
  include/clang/Analysis/AnalysisDeclContext.h
  include/clang/Analysis/CFG.h
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/Analysis/AnalysisDeclContext.cpp
  lib/Analysis/CFG.cpp
  lib/StaticAnalyzer/Core/AnalysisManager.cpp
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/analyzer-config.c
  test/Analysis/analyzer-config.cpp
  test/Analysis/scopes-cfg-output.cpp

Index: test/Analysis/scopes-cfg-output.cpp
===
--- /dev/null
+++ test/Analysis/scopes-cfg-output.cpp
@@ -0,0 +1,1168 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-scopes=true %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s
+
+class A {
+public:
+// CHECK:  [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  A() {}
+
+// CHECK:  [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  ~A() {}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: 1
+// CHECK-NEXT:   2: return [B1.1];
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  operator int() const { return 1; }
+};
+
+int getX();
+extern const bool UV;
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A [2])
+// CHECK-NEXT:   3: A a[2];
+// CHECK-NEXT:   4:  (CXXConstructExpr, class A [0])
+// CHECK-NEXT:   5: A b[0];
+// CHECK-NEXT:   6: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_array() {
+  A a[2];
+  A b[0];
+}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: CFGScopeBegin(c)
+// CHECK-NEXT:   5:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   6: A c;
+// CHECK-NEXT:   7:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   8: A d;
+// CHECK-NEXT:   9: [B1.8].~A() (Implicit destructor)
+// CHECK-NEXT:  10: [B1.6].~A() (Implicit destructor)
+// CHECK-NEXT:  11: CFGScopeEnd(c)
+// CHECK-NEXT:  12:  (CXXConstructExpr, class A)
+// CHECK-NEXT:  13: A b;
+// CHECK-NEXT:  14: [B1.13].~A() (Implicit destructor)
+// CHECK-NEXT:  15: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:  16: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_scope() {
+  A a;
+  { A c;
+A d;
+  }
+  A b;
+}
+
+// CHECK:  [B4 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B3
+// CHECK:  [B1]
+// CHECK-NEXT:   1:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   2: A c;
+// CHECK-NEXT:   3: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   5: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   6: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B2]
+// CHECK-NEXT:   1: return;
+// CHECK-NEXT:   2: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   3: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   4: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B3]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   5: A b;
+// CHECK-NEXT:   6: UV
+// CHECK-NEXT:   7: [B3.6] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B3.7]
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (2): B2 B1
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (2): B1 B2
+void test_return() {
+  A a;
+  A b;
+  if (UV) return;
+  A c;
+}
+
+// CHECK:  [B5 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:  [B1]
+// CHECK-NEXT:   1: [B4.8].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(b)
+// CHECK-NEXT:   3: [B4.3].~A() (Implicit destructor)
+// CHECK-NEXT:   4: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (2): B2 B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B2]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A c;
+// CHECK-NEXT:   4: [B2.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(c)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-

[PATCH] D42800: Let CUDA toolchain support amdgpu target

2018-02-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D42800#994955, @Hahnfeld wrote:

> Only commenting on parts that I'm a bit familiar with. In general, does it 
> make sense to split this patch, are there different "stages" of support? Like 
> 1) being able to compile an empty file, 2) generate optimized code, 3) allow 
> using math functions?


Good suggestion. Actually this patch is mainly to let the toolchain recognise 
the amdgpu implementation of CUDA and create proper stages. I can try to create 
a test for compiling an empty file.


https://reviews.llvm.org/D42800



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


[PATCH] D42530: Clang permits assignment to vector/extvector elements in a const method

2018-02-01 Thread Andrew V. Tischenko via Phabricator via cfe-commits
avt77 added a comment.

In fact we have here another problem: it is not an attempt to assign to const 
variable but it is an attempt to use the field assingment inside const  method: 
I'm working on it.


https://reviews.llvm.org/D42530



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


[PATCH] D42730: [clang-tidy]] Add check for use of types/classes/functions from header which are deprecated and removed in C++17

2018-02-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/modernize/AvoidFunctionalCheck.h:19
+
+/// Check for several deprecated types and classes from  header
+///

alexfh wrote:
> aaron.ballman wrote:
> > alexfh wrote:
> > > Quuxplusone wrote:
> > > > aaron.ballman wrote:
> > > > > alexfh wrote:
> > > > > > alexfh wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > massberg wrote:
> > > > > > > > > massberg wrote:
> > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > Missing full stop at the end of the sentence.
> > > > > > > > > > > 
> > > > > > > > > > > Why should this modernize check be limited to 
> > > > > > > > > > > ``? Just like we have a "deprecated headers" 
> > > > > > > > > > > check, perhaps this should be a "deprecated APIs" check?
> > > > > > > > > > Added full stop.
> > > > > > > > > > 
> > > > > > > > > > I'm not sure if this check should be limited to 
> > > > > > > > > >  or be extended to a full 'deprecated API' 
> > > > > > > > > > check.
> > > > > > > > > > This change is just a start, several more types and classes 
> > > > > > > > > > which are removed from  will follow, e.g:
> > > > > > > > > > 
> > > > > > > > > > - std::ptr_fun, std::mem_fun, std::mem_fun_ref
> > > > > > > > > > - std::bind1st, std::bind2nd
> > > > > > > > > > - std::unary_function, std::binary_function
> > > > > > > > > > - std::pointer_to_unary_function, 
> > > > > > > > > > std::pointer_to_binary_function, std::mem_fun_t, 
> > > > > > > > > > std::mem_fun1_t, std::const_mem_fun_t, 
> > > > > > > > > > - std::const_mem_fun1_t, std::mem_fun_ref_t, 
> > > > > > > > > > std::mem_fun1_ref_t, std::const_mem_fun_ref_t, 
> > > > > > > > > > std::const_mem_fun1_ref_t
> > > > > > > > > > - std::binder1st, std::binder2nd
> > > > > > > > > > 
> > > > > > > > > > As these are a bunch of functions and types, in my eyes a 
> > > > > > > > > > check just for  is fine. But I'm also fine with 
> > > > > > > > > > a general 'deprecated API' check.
> > > > > > > > > > Alex, can you comment on this?
> > > > > > > > > There are already other checks for functions which are 
> > > > > > > > > removed in C++17 like modernize-replace-random-shuffle.
> > > > > > > > > So I think having an separate check for functions and types 
> > > > > > > > > removed from  would be OK.
> > > > > > > > You've hit the nail on the head for what I'm trying to avoid -- 
> > > > > > > > we shouldn't have multiple checks unless they do drastically 
> > > > > > > > different things. Having a deprecated check like this really 
> > > > > > > > only makes sense for APIs that are deprecated but aren't 
> > > > > > > > uniformly marked as `[[deprecated]]` by the library. As such, I 
> > > > > > > > think we really only need one check for this rather than 
> > > > > > > > splitting it out over multiple checks -- the existing check 
> > > > > > > > functionality could be rolled into this one and its check 
> > > > > > > > become an alias.
> > > > > > > > I'm not sure if this check should be limited to  or 
> > > > > > > > be extended to a full 'deprecated API' check.
> > > > > > > 
> > > > > > > IIUC, it should be possible to implement fixits at least for some 
> > > > > > > use cases here. My impression was that Jens was at least 
> > > > > > > considering to work on fixits. The other check mentioned here - 
> > > > > > > `modernize-replace-random-shuffle` already implements fixits. 
> > > > > > > Fixits are specific to the API and some codebases may have better 
> > > > > > > replacement APIs than what the standard suggests, so different 
> > > > > > > users may want to apply different set of the fixes. Given all 
> > > > > > > that, I wouldn't just merge all of the checks dealing with 
> > > > > > > deprecated APIs. Splitting them at least by header seems like a 
> > > > > > > good start, maybe even finer granularity may be needed in some 
> > > > > > > cases.
> > > > > > TL;DR "they do drastically different things" is the case for this 
> > > > > > check and modernize-replace-random-shuffle.
> > > > > I disagree that they do drastically different things or that fix-its 
> > > > > are a problem. Some of these APIs have replacements, others do not. 
> > > > > At the end of the day, the basics are the same: the functionality is 
> > > > > deprecated and you should consider a replacement. Sometimes we know 
> > > > > that replacement up front, other times we don't. I don't think we 
> > > > > should make users reach for a per-header file answer to that problem 
> > > > > unless it provides them some benefit. I don't see users caring to 
> > > > > update  but not other headers.
> > > > > 
> > > > > I can see benefit to splitting the *implementations* of the checks 
> > > > > along arbitrary lines, but how we structure the implementation is 
> > > > > orthogonal to how we surface the functionality.
> > > > This sounds like clang-tidy ought to have an umbrella option here, 
> > > > analogous to how -Wformat turns

[PATCH] D42736: [DebugInfo] Improvements to representation of enumeration types (PR36168)

2018-02-01 Thread Momchil Velikov via Phabricator via cfe-commits
chill updated this revision to Diff 132414.
chill added a comment.

Minor update, the parameter to `createEnumerator` is `IsUnsigned` now (instead 
of `IsSigned`), changed caller.


https://reviews.llvm.org/D42736

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGen/debug-info-enum.cpp
  test/CodeGenCXX/debug-info-enum-class.cpp
  test/CodeGenCXX/debug-info-enum.cpp
  test/Modules/ModuleDebugInfo.cpp

Index: test/Modules/ModuleDebugInfo.cpp
===
--- test/Modules/ModuleDebugInfo.cpp
+++ test/Modules/ModuleDebugInfo.cpp
@@ -48,7 +48,7 @@
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
 // CHECK-NOT:  name:
 // CHECK-SAME: )
-// CHECK: !DIEnumerator(name: "e5", value: 5)
+// CHECK: !DIEnumerator(name: "e5", value: 5, isUnsigned: true)
 
 // CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "B",
 // no mangled name here yet.
Index: test/CodeGenCXX/debug-info-enum.cpp
===
--- test/CodeGenCXX/debug-info-enum.cpp
+++ test/CodeGenCXX/debug-info-enum.cpp
@@ -11,7 +11,7 @@
 // CHECK-SAME:  identifier: "_ZTSN5test11eE"
 // CHECK: [[TEST1]] = !DINamespace(name: "test1"
 // CHECK: [[TEST1_ENUMS]] = !{[[TEST1_E:![0-9]*]]}
-// CHECK: [[TEST1_E]] = !DIEnumerator(name: "E", value: 0)
+// CHECK: [[TEST1_E]] = !DIEnumerator(name: "E", value: 0, isUnsigned: true)
 enum e { E };
 void foo() {
   int v = E;
Index: test/CodeGenCXX/debug-info-enum-class.cpp
===
--- test/CodeGenCXX/debug-info-enum-class.cpp
+++ test/CodeGenCXX/debug-info-enum-class.cpp
@@ -15,20 +15,20 @@
 // CHECK-SAME: baseType: ![[INT:[0-9]+]]
 // CHECK-SAME: size: 32
 // CHECK-NOT:  offset:
-// CHECK-NOT:  flags:
+// CHECK-SAME: flags: DIFlagFixedEnum
 // CHECK-SAME: ){{$}}
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "B"
 // CHECK-SAME: line: 4
 // CHECK-SAME: baseType: ![[ULONG:[0-9]+]]
 // CHECK-SAME: size: 64
 // CHECK-NOT:  offset:
-// CHECK-NOT:  flags:
+// CHECK-SAME: flags: DIFlagFixedEnum
 // CHECK-SAME: ){{$}}
 // CHECK: ![[ULONG]] = !DIBasicType(name: "long unsigned int"
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "C"
 // CHECK-SAME: line: 5
-// CHECK-NOT:  baseType:
+// CHECK-SAME: baseType: ![[ULONG:[0-9]+]]
 // CHECK-SAME: size: 32
 // CHECK-NOT:  offset:
 // CHECK-NOT:  flags:
Index: test/CodeGen/debug-info-enum.cpp
===
--- /dev/null
+++ test/CodeGen/debug-info-enum.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang -target x86_64-linux -g -S -emit-llvm -o - %s | FileCheck %s
+enum class E0 : signed char {
+  A0 = -128,
+  B0 = 127,
+} x0;
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E0"
+// CHECK-SAME: flags: DIFlagFixedEnum
+// CHECK: !DIBasicType(name: "signed char", size: 8, encoding: DW_ATE_signed_char)
+// CHECK: !DIEnumerator(name: "A0", value: -128)
+// CHECK: !DIEnumerator(name: "B0", value: 127)
+
+enum class E1 : unsigned char { A1 = 255 } x1;
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E1"
+// CHECK-SAME: flags: DIFlagFixedEnum
+// CHECK: !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
+// CHECK: !DIEnumerator(name: "A1", value: 255, isUnsigned: true)
+
+enum class E2 : signed short {
+  A2 = -32768,
+  B2 = 32767,
+} x2;
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E2"
+// CHECK-SAME: flags: DIFlagFixedEnum
+// CHECK: !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)
+// CHECK: !DIEnumerator(name: "A2", value: -32768)
+// CHECK: !DIEnumerator(name: "B2", value: 32767)
+
+enum class E3 : unsigned short { A3 = 65535 } x3;
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E3"
+// CHECK-SAME: DIFlagFixedEnum
+// CHECK: !DIBasicType(name: "unsigned short", size: 16, encoding: DW_ATE_unsigned)
+// CHECK: !DIEnumerator(name: "A3", value: 65535, isUnsigned: true)
+
+enum class E4 : signed int { A4 = -2147483648, B4 = 2147483647 } x4;
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E4"
+// CHECK-SAME: flags: DIFlagFixedEnum
+// CHECK: ![[INT:[0-9]+]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+// CHECK: !DIEnumerator(name: "A4", value: -2147483648)
+// CHECK: !DIEnumerator(name: "B4", value: 2147483647)
+
+enum class E5 : unsigned int { A5 = 4294967295 } x5;
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E5"
+// CHECK-SAME: flags: DIFlagFixedEnum
+// CHECK: !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+// CHECK: !DIEnumerator(name: "A5", value: 4294

[PATCH] D42800: Let CUDA toolchain support amdgpu target

2018-02-01 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: lib/Basic/Targets/AMDGPU.cpp:437
+  case CudaArch::UNKNOWN:
+assert(false && "No GPU arch when compiling CUDA device code.");
+return "";

llvm_unreachable



Comment at: lib/Driver/ToolChains/Cuda.cpp:359-361
+  addBCLib(C, Args, CmdArgs, LibraryPaths, "opencl.amdgcn.bc");
+  addBCLib(C, Args, CmdArgs, LibraryPaths, "ockl.amdgcn.bc");
+  addBCLib(C, Args, CmdArgs, LibraryPaths, "irif.amdgcn.bc");

Why is this done under an NVPTX:: class



Comment at: lib/Driver/ToolChains/Cuda.cpp:390
+  else {
+OptArgs.push_back(Args.MakeArgString("-O2"));
+OptArgs.push_back("-S");

Why is this hardcoded?


https://reviews.llvm.org/D42800



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


[PATCH] D42736: [DebugInfo] Improvements to representation of enumeration types (PR36168)

2018-02-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: test/CodeGen/debug-info-enum.cpp:2
+// RUN: %clang -target x86_64-linux -g -S -emit-llvm -o - %s | FileCheck %s
+enum class E0 : signed char {
+  A0 = -128,

Could you summarize the purpose of each of these tests (possibly in a comment 
above the enum in each case) - there look to be more test cases than I'd 
imagine being necessary, but I haven't carefully analyzed them.

For example: I wouldn't expect to test every integer type, if the code handling 
them is general enough to be demonstrated by one or two cases?



Comment at: test/CodeGen/debug-info-enum.cpp:6-10
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E0"
+// CHECK-SAME: flags: DIFlagFixedEnum
+// CHECK: !DIBasicType(name: "signed char", size: 8, encoding: 
DW_ATE_signed_char)
+// CHECK: !DIEnumerator(name: "A0", value: -128)
+// CHECK: !DIEnumerator(name: "B0", value: 127)

Rather than relying on specific ordering of output, generally you should test 
that the actual references across different metadata records are correct (eg: 
check that the DICompositeType's member list elements are the DIEnumerators 
(use named matches, rather than hardcoding the metadata node numbers))

Though, admittedly, this is a lot easier to read as-is. 



Comment at: test/CodeGen/debug-info-enum.cpp:66
+// CHECK-SAME: baseType: ![[INT]]
+// CHECK-NOT: flags: DIFlagFixedEnum
+// CHECK: !DIEnumerator(name: "A8", value: -128)

Probably drop the "flags: " part of this NOT check - so that if other flags are 
added, this won't be overly constrained (eg: if this type ended up with "flags: 
X | DIFlagFixedEnum" this NOT check as-is wouldn't catch the regression)


https://reviews.llvm.org/D42736



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


r323986 - Mark fallthrough with LLVM_FALLTHROUGH

2018-02-01 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Thu Feb  1 10:10:20 2018
New Revision: 323986

URL: http://llvm.org/viewvc/llvm-project?rev=323986&view=rev
Log:
Mark fallthrough with LLVM_FALLTHROUGH

Modified:
cfe/trunk/utils/TableGen/NeonEmitter.cpp

Modified: cfe/trunk/utils/TableGen/NeonEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/NeonEmitter.cpp?rev=323986&r1=323985&r2=323986&view=diff
==
--- cfe/trunk/utils/TableGen/NeonEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/NeonEmitter.cpp Thu Feb  1 10:10:20 2018
@@ -948,7 +948,7 @@ void Type::applyModifier(char Mod) {
 break;
   case 'c':
 Constant = true;
-  // Fall through
+LLVM_FALLTHROUGH;
   case 'p':
 Pointer = true;
 Bitwidth = ElementBitwidth;


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


[PATCH] D42803: [clangd] Log dropped diagnostics.

2018-02-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clangd/ClangdUnit.cpp:182
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+

does Message include file:line? we probably want that in the log line.



Comment at: clangd/ClangdUnit.cpp:186
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+log("Ignored diagnostic outside main file: " + Twine(Message));
 return llvm::None;

Agree this is useful.

Have we turned off the diagnostics limit (or will we?) a misconfig of e.g. C vs 
C++ parsing of a header seems like it could produce 1000+ log lines from 
preamble that we should probably avoid somehow.
(Maybe even avoid paying to format)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42803



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


[PATCH] D42800: Let CUDA toolchain support amdgpu target

2018-02-01 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

I don't have enough knowledge about compute on AMD's GPU and would appreciate 
if you could share your thoughts on how you think CUDA on AMD should work. Is 
there a good document describing how compute currently works (how do I launch a 
kernel using rough equivalent of nvidia's driver API 
 ) on AMD GPUs?

- Headers. clang pre-includes *a lot* of headers from NVidia's CUDA SDK. Some 
of them may work for AMD, but some certainly will not -- there are a lot of 
headers with nvidia-specific inline assembly or things that rely on 
nvidia-specific functionality. In the end, I think, we'll need some sort of 
CUDA SDK for AMD which would implement (possibly with asserts for unsupported 
functions) existing CUDA APIs. Or, perhaps the plan is to just use CUDA 
**syntax** only without providing complete API compatibility with nvidia.

- How will GPU-side object file be incorporated into the final executable? I 
believe OpenMP has a fairly generic way to deal with it in clang. I'm not sure 
if that would be suitable for use with AMD's runtime (whatever we need to use 
to launch the kernels).

- Launching kernels. Will it be similar to the way kernel launches are 
configured on NVidia? I.e. grid of blocks of threads with per-block shared 
memory.


https://reviews.llvm.org/D42800



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


[PATCH] D17700: [clang-format] Proposal for changes to Objective-C block formatting

2018-02-01 Thread Daniel Casadevall Pino via Phabricator via cfe-commits
dcasadevall added a comment.

Was this lost in the woods? I believe this is a valid change when working in 
Objective-C


https://reviews.llvm.org/D17700



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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-01 Thread Kuba (Brecka) Mracek via Phabricator via cfe-commits
kubamracek added a comment.

> This is our first patch so we're unfamiliar with the LLVM testing 
> infrastructure. Could you please tell us what kind of test you'd like? An 
> example would also be great.

Thank you for your first contribution! I'm going to comment on the testing 
infrastructure only, as I don't know the answer to the portability/mangling/ABI 
question.

Most user-visible features of ASan can usually be demonstrated in a single-file 
test that is completely standalone test program. E.g. ASan's ability to detect 
heap buffer overflows is demonstrated in `test/asan/TestCases/heap-overflow.cc` 
file. Notice that these tests don't include or reference any sanitizer internal 
functions. They are meant to be written in a way that user's code is written. 
Can you try adding such a test, which would be a standalone .cc file that would 
demonstrate the problematic scenario (C++ exception rethrow) without including 
ASan headers? The test's expectation should be that ASan doesn't report any 
issues, whereas without your patch, the test fails (or might fail). For an 
example of a negative test (that checks that ASan *doesn't* report any issues), 
see `test/asan/TestCases/Darwin/nil-return-struct.mm`.

If the test should work on all ASan supported platforms, put it directly into 
`test/asan/TestCases`. If it's POSIX-only, place it under `Posix/` subdirectory.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644



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


[PATCH] D17700: [clang-format] Proposal for changes to Objective-C block formatting

2018-02-01 Thread Kent Sutherland via Phabricator via cfe-commits
ksuther added a comment.

It seems to have been. I've been using a modified version of clang-format with 
this change applied (as well as http://reviews.llvm.org/D17922) since I 
submitted this.


https://reviews.llvm.org/D17700



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


[libcxx] r323989 - Put the exception classes for experimental::optional and experimental::any back in the dylib for binary compatibility

2018-02-01 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Feb  1 10:45:57 2018
New Revision: 323989

URL: http://llvm.org/viewvc/llvm-project?rev=323989&view=rev
Log:
Put the exception classes for experimental::optional and experimental::any back 
in the dylib for binary compatibility

Modified:
libcxx/trunk/src/any.cpp
libcxx/trunk/src/optional.cpp

Modified: libcxx/trunk/src/any.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/any.cpp?rev=323989&r1=323988&r2=323989&view=diff
==
--- libcxx/trunk/src/any.cpp (original)
+++ libcxx/trunk/src/any.cpp Thu Feb  1 10:45:57 2018
@@ -14,3 +14,22 @@ const char* bad_any_cast::what() const _
 return "bad any cast";
 }
 }
+
+
+#include 
+
+//  Preserve std::experimental::any_bad_cast for ABI compatibility
+//  Even though it no longer exists in a header file
+_LIBCPP_BEGIN_NAMESPACE_LFTS
+
+class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : 
public bad_cast
+{
+public:
+virtual const char* what() const _NOEXCEPT;
+};
+
+const char* bad_any_cast::what() const _NOEXCEPT {
+return "bad any cast";
+}
+
+_LIBCPP_END_NAMESPACE_LFTS

Modified: libcxx/trunk/src/optional.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/optional.cpp?rev=323989&r1=323988&r2=323989&view=diff
==
--- libcxx/trunk/src/optional.cpp (original)
+++ libcxx/trunk/src/optional.cpp Thu Feb  1 10:45:57 2018
@@ -20,3 +20,23 @@ const char* bad_optional_access::what()
 
 } // std
 
+
+#include 
+
+//  Preserve std::experimental::bad_optional_access for ABI compatibility
+//  Even though it no longer exists in a header file
+_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
+
+class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS 
bad_optional_access
+: public std::logic_error
+{
+public:
+   bad_optional_access() : std::logic_error("Bad optional Access") {}
+
+// Get the key function ~bad_optional_access() into the dylib
+virtual ~bad_optional_access() _NOEXCEPT;
+};
+
+bad_optional_access::~bad_optional_access() _NOEXCEPT = default;
+
+_LIBCPP_END_NAMESPACE_EXPERIMENTAL


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


[PATCH] D42803: [clangd] Log dropped diagnostics.

2018-02-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 132430.
ilya-biryukov added a comment.

- Show location of dropped diagnostic.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42803

Files:
  clangd/ClangdUnit.cpp


Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -178,15 +179,30 @@
 llvm::Optional toClangdDiag(const clang::Diagnostic &D,
 DiagnosticsEngine::Level Level,
 const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-  !D.getSourceManager().isInMainFile(D.getLocation()))
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+
+SmallString<64> Location;
+if (D.hasSourceManager() && D.getLocation().isValid()) {
+  auto &SourceMgr = D.getSourceManager();
+  auto Loc = SourceMgr.getFileLoc(D.getLocation());
+  llvm::raw_svector_ostream OS(Location);
+  Loc.print(OS, SourceMgr);
+} else {
+  Location = "";
+}
+
+log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}",
+  Location, Message));
 return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
 Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));


Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -178,15 +179,30 @@
 llvm::Optional toClangdDiag(const clang::Diagnostic &D,
 DiagnosticsEngine::Level Level,
 const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-  !D.getSourceManager().isInMainFile(D.getLocation()))
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+
+SmallString<64> Location;
+if (D.hasSourceManager() && D.getLocation().isValid()) {
+  auto &SourceMgr = D.getSourceManager();
+  auto Loc = SourceMgr.getFileLoc(D.getLocation());
+  llvm::raw_svector_ostream OS(Location);
+  Loc.print(OS, SourceMgr);
+} else {
+  Location = "";
+}
+
+log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}",
+  Location, Message));
 return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
 Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r323992 - [clangd] Log dropped diagnostics.

2018-02-01 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Feb  1 11:06:45 2018
New Revision: 323992

URL: http://llvm.org/viewvc/llvm-project?rev=323992&view=rev
Log:
[clangd] Log dropped diagnostics.

Summary:
clangd drops diagnostics coming outside the main file, but it is still
useful to see that something went wrong in the logs.

Reviewers: hokein, ioeric, sammccall

Reviewed By: sammccall

Subscribers: klimek, jkorous-apple, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=323992&r1=323991&r2=323992&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Feb  1 11:06:45 2018
@@ -27,6 +27,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -178,15 +179,30 @@ TextEdit toTextEdit(const FixItHint &Fix
 llvm::Optional toClangdDiag(const clang::Diagnostic &D,
 DiagnosticsEngine::Level Level,
 const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-  !D.getSourceManager().isInMainFile(D.getLocation()))
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+
+SmallString<64> Location;
+if (D.hasSourceManager() && D.getLocation().isValid()) {
+  auto &SourceMgr = D.getSourceManager();
+  auto Loc = SourceMgr.getFileLoc(D.getLocation());
+  llvm::raw_svector_ostream OS(Location);
+  Loc.print(OS, SourceMgr);
+} else {
+  Location = "";
+}
+
+log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}",
+  Location, Message));
 return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
 Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));


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


[PATCH] D42803: [clangd] Log dropped diagnostics.

2018-02-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdUnit.cpp:182
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+

sammccall wrote:
> does Message include file:line? we probably want that in the log line.
No, it didn't include the line before. Now dumping the location too.



Comment at: clangd/ClangdUnit.cpp:186
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+log("Ignored diagnostic outside main file: " + Twine(Message));
 return llvm::None;

sammccall wrote:
> Agree this is useful.
> 
> Have we turned off the diagnostics limit (or will we?) a misconfig of e.g. C 
> vs C++ parsing of a header seems like it could produce 1000+ log lines from 
> preamble that we should probably avoid somehow.
> (Maybe even avoid paying to format)
I don't think we have changed default clang behavior.
This look like a good use-case for introducing log levels.
This information is definitely too verbose most of the time, but very useful 
when debugging failures


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42803



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


[PATCH] D42803: [clangd] Log dropped diagnostics.

2018-02-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL323992: [clangd] Log dropped diagnostics. (authored by 
ibiryukov, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42803

Files:
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp


Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -178,15 +179,30 @@
 llvm::Optional toClangdDiag(const clang::Diagnostic &D,
 DiagnosticsEngine::Level Level,
 const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-  !D.getSourceManager().isInMainFile(D.getLocation()))
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+
+SmallString<64> Location;
+if (D.hasSourceManager() && D.getLocation().isValid()) {
+  auto &SourceMgr = D.getSourceManager();
+  auto Loc = SourceMgr.getFileLoc(D.getLocation());
+  llvm::raw_svector_ostream OS(Location);
+  Loc.print(OS, SourceMgr);
+} else {
+  Location = "";
+}
+
+log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}",
+  Location, Message));
 return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
 Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));


Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -178,15 +179,30 @@
 llvm::Optional toClangdDiag(const clang::Diagnostic &D,
 DiagnosticsEngine::Level Level,
 const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-  !D.getSourceManager().isInMainFile(D.getLocation()))
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+
+SmallString<64> Location;
+if (D.hasSourceManager() && D.getLocation().isValid()) {
+  auto &SourceMgr = D.getSourceManager();
+  auto Loc = SourceMgr.getFileLoc(D.getLocation());
+  llvm::raw_svector_ostream OS(Location);
+  Loc.print(OS, SourceMgr);
+} else {
+  Location = "";
+}
+
+log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}",
+  Location, Message));
 return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
 Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42803: [clangd] Log dropped diagnostics.

2018-02-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE323992: [clangd] Log dropped diagnostics. (authored by 
ibiryukov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42803?vs=132430&id=132432#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42803

Files:
  clangd/ClangdUnit.cpp


Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -178,15 +179,30 @@
 llvm::Optional toClangdDiag(const clang::Diagnostic &D,
 DiagnosticsEngine::Level Level,
 const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-  !D.getSourceManager().isInMainFile(D.getLocation()))
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+
+SmallString<64> Location;
+if (D.hasSourceManager() && D.getLocation().isValid()) {
+  auto &SourceMgr = D.getSourceManager();
+  auto Loc = SourceMgr.getFileLoc(D.getLocation());
+  llvm::raw_svector_ostream OS(Location);
+  Loc.print(OS, SourceMgr);
+} else {
+  Location = "";
+}
+
+log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}",
+  Location, Message));
 return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
 Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));


Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -178,15 +179,30 @@
 llvm::Optional toClangdDiag(const clang::Diagnostic &D,
 DiagnosticsEngine::Level Level,
 const LangOptions &LangOpts) {
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   if (!D.hasSourceManager() || !D.getLocation().isValid() ||
-  !D.getSourceManager().isInMainFile(D.getLocation()))
+  !D.getSourceManager().isInMainFile(D.getLocation())) {
+
+SmallString<64> Location;
+if (D.hasSourceManager() && D.getLocation().isValid()) {
+  auto &SourceMgr = D.getSourceManager();
+  auto Loc = SourceMgr.getFileLoc(D.getLocation());
+  llvm::raw_svector_ostream OS(Location);
+  Loc.print(OS, SourceMgr);
+} else {
+  Location = "";
+}
+
+log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}",
+  Location, Message));
 return llvm::None;
+  }
 
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
-  SmallString<64> Message;
-  D.FormatDiagnostic(Message);
   Result.Diag.message = Message.str();
   for (const FixItHint &Fix : D.getFixItHints())
 Result.FixIts.push_back(toTextEdit(Fix, D.getSourceManager(), LangOpts));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r323155 - Introduce the "retpoline" x86 mitigation technique for variant #2 of the speculative execution vulnerabilities disclosed today, specifically identified by CVE-2017-5715, "Branch Target

2018-02-01 Thread Chandler Carruth via cfe-commits
+Hans Wennborg  +tstel...@redhat.com


So the retpoline patch series we should get back ported start with this
revision and have two follow ups:
r323155
r323288
r323915

+Reid Kleckner  was going to look at doing the (likely more
involved) backport to the 5 branch

On Mon, Jan 22, 2018 at 2:06 PM Chandler Carruth via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: chandlerc
> Date: Mon Jan 22 14:05:25 2018
> New Revision: 323155
>
> URL: http://llvm.org/viewvc/llvm-project?rev=323155&view=rev
> Log:
> Introduce the "retpoline" x86 mitigation technique for variant #2 of the
> speculative execution vulnerabilities disclosed today, specifically
> identified by CVE-2017-5715, "Branch Target Injection", and is one of the
> two halves to Spectre..
>
> Summary:
> First, we need to explain the core of the vulnerability. Note that this
> is a very incomplete description, please see the Project Zero blog post
> for details:
>
> https://googleprojectzero.blogspot.com/2018/01/reading-privileged-memory-with-side.html
>
> The basis for branch target injection is to direct speculative execution
> of the processor to some "gadget" of executable code by poisoning the
> prediction of indirect branches with the address of that gadget. The
> gadget in turn contains an operation that provides a side channel for
> reading data. Most commonly, this will look like a load of secret data
> followed by a branch on the loaded value and then a load of some
> predictable cache line. The attacker then uses timing of the processors
> cache to determine which direction the branch took *in the speculative
> execution*, and in turn what one bit of the loaded value was. Due to the
> nature of these timing side channels and the branch predictor on Intel
> processors, this allows an attacker to leak data only accessible to
> a privileged domain (like the kernel) back into an unprivileged domain.
>
> The goal is simple: avoid generating code which contains an indirect
> branch that could have its prediction poisoned by an attacker. In many
> cases, the compiler can simply use directed conditional branches and
> a small search tree. LLVM already has support for lowering switches in
> this way and the first step of this patch is to disable jump-table
> lowering of switches and introduce a pass to rewrite explicit indirectbr
> sequences into a switch over integers.
>
> However, there is no fully general alternative to indirect calls. We
> introduce a new construct we call a "retpoline" to implement indirect
> calls in a non-speculatable way. It can be thought of loosely as
> a trampoline for indirect calls which uses the RET instruction on x86.
> Further, we arrange for a specific call->ret sequence which ensures the
> processor predicts the return to go to a controlled, known location. The
> retpoline then "smashes" the return address pushed onto the stack by the
> call with the desired target of the original indirect call. The result
> is a predicted return to the next instruction after a call (which can be
> used to trap speculative execution within an infinite loop) and an
> actual indirect branch to an arbitrary address.
>
> On 64-bit x86 ABIs, this is especially easily done in the compiler by
> using a guaranteed scratch register to pass the target into this device.
> For 32-bit ABIs there isn't a guaranteed scratch register and so several
> different retpoline variants are introduced to use a scratch register if
> one is available in the calling convention and to otherwise use direct
> stack push/pop sequences to pass the target address.
>
> This "retpoline" mitigation is fully described in the following blog
> post: https://support.google.com/faqs/answer/7625886
>
> We also support a target feature that disables emission of the retpoline
> thunk by the compiler to allow for custom thunks if users want them.
> These are particularly useful in environments like kernels that
> routinely do hot-patching on boot and want to hot-patch their thunk to
> different code sequences. They can write this custom thunk and use
> `-mretpoline-external-thunk` *in addition* to `-mretpoline`. In this
> case, on x86-64 thu thunk names must be:
> ```
>   __llvm_external_retpoline_r11
> ```
> or on 32-bit:
> ```
>   __llvm_external_retpoline_eax
>   __llvm_external_retpoline_ecx
>   __llvm_external_retpoline_edx
>   __llvm_external_retpoline_push
> ```
> And the target of the retpoline is passed in the named register, or in
> the case of the `push` suffix on the top of the stack via a `pushl`
> instruction.
>
> There is one other important source of indirect branches in x86 ELF
> binaries: the PLT. These patches also include support for LLD to
> generate PLT entries that perform a retpoline-style indirection.
>
> The only other indirect branches remaining that we are aware of are from
> precompiled runtimes (such as crt0.o and similar). The ones we have
> found are not really attackable, and so we have not focused on them
> here, but eventually t

[PATCH] D42785: [Analyzer] Fix a typo in `ExprEngine::VisitMemberExpr`

2018-02-01 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.

Ew. So it means that checker transitions are currently discarded. Great catch. 
I guess we don't use this functionality yet, so we can't test it, but the fix 
should definitely go in.

Then, again, i'm suspecting that you may want to use `checkLocation` or 
`checkBind` instead of `checkPreStmt` - i doubt that there's 
anything special about member expressions that make them different from other 
sorts of bindings. And if you're tracking how a symbol is assigned to a field 
of the structure - well, you shouldn't, this info is already in the program 
state and you can retrieve it any time with `getSVal(Region)`.


Repository:
  rC Clang

https://reviews.llvm.org/D42785



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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-01 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Could you please reformat it?
With git I usually use: git clang-format -f --style=file HEAD^


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644



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


[PATCH] D42530: Clang permits assignment to vector/extvector elements in a const method

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

That's still just const-propagation.  The const qualifier on the pointee type 
of this should propagate to the l-value resulting from the member access, and 
the vector-specific projection logic should continue to propagate const to the 
type of the element l-value.


https://reviews.llvm.org/D42530



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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-01 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

I would not worry about cross platform here. You can patch just Linux and 
whoever have access (and issues) on other platforms can send a patch with 
similar changes.
Mac should use libc++.
I'd put the test outside of Posix, and mark failing platforms as "// XFAIL:", 
temporarily, as we suppose to handle all of them.




Comment at: lib/asan/asan_interceptors.cc:327
+INTERCEPTOR(void, __cxa_rethrow_primary_exception, void *a) {
+  CHECK(REAL(__cxa_throw));
+  __asan_handle_no_return();

Should this be: CHECK(REAL(__cxa_rethrow_primary_exception)); ?



Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644



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


[PATCH] D42810: [Sema] Add implicit members even for invalid CXXRecordDecls

2018-02-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: bkramer.

It should be safe, since other code paths are already generating
implicit members even in invalid CXXRecordDecls (e.g. lookup).

If we don't generate implicit members on CXXRecordDecl's completion,
they will be generated by next lookup of constructors. This causes a
crash when the following conditions are met:

- a CXXRecordDecl is invalid,
- it is provided via ExternalASTSource (e.g. from PCH),
- it has inherited constructors (they create as ShadowDecl),
- lookup of its constructors was not run before ASTWriter serialized it.

This causes the ShadowDecls created for implicit constructors to be
removed from the class, but that's no longer possible since class is
provided by ExternalASTSource.

See provided lit test for an example.


Repository:
  rC Clang

https://reviews.llvm.org/D42810

Files:
  lib/Sema/SemaDecl.cpp
  test/Index/Inputs/crash-preamble-classes.h
  test/Index/crash-preamble-classes.cpp


Index: test/Index/crash-preamble-classes.cpp
===
--- /dev/null
+++ test/Index/crash-preamble-classes.cpp
@@ -0,0 +1,8 @@
+#include "crash-preamble-classes.h"
+
+struct Z : Y {
+  Z() {}
+};
+
+// RUN: env CINDEXTEST_EDITING=1 \
+// RUN: c-index-test -test-load-source-reparse 5 local -I %S/Inputs %s
Index: test/Index/Inputs/crash-preamble-classes.h
===
--- /dev/null
+++ test/Index/Inputs/crash-preamble-classes.h
@@ -0,0 +1,9 @@
+struct Incomplete;
+
+struct X : Incomplete {
+  X();
+};
+
+struct Y : X {
+  using X::X;
+};
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -15430,10 +15430,10 @@
   CXXRecord->getDestructor());
 }
 
-if (!CXXRecord->isInvalidDecl()) {
-  // Add any implicitly-declared members to this class.
-  AddImplicitlyDeclaredMembersToClass(CXXRecord);
+// Add any implicitly-declared members to this class.
+AddImplicitlyDeclaredMembersToClass(CXXRecord);
 
+if (!CXXRecord->isInvalidDecl()) {
   // If we have virtual base classes, we may end up finding multiple
   // final overriders for a given virtual function. Check for this
   // problem now.


Index: test/Index/crash-preamble-classes.cpp
===
--- /dev/null
+++ test/Index/crash-preamble-classes.cpp
@@ -0,0 +1,8 @@
+#include "crash-preamble-classes.h"
+
+struct Z : Y {
+  Z() {}
+};
+
+// RUN: env CINDEXTEST_EDITING=1 \
+// RUN: c-index-test -test-load-source-reparse 5 local -I %S/Inputs %s
Index: test/Index/Inputs/crash-preamble-classes.h
===
--- /dev/null
+++ test/Index/Inputs/crash-preamble-classes.h
@@ -0,0 +1,9 @@
+struct Incomplete;
+
+struct X : Incomplete {
+  X();
+};
+
+struct Y : X {
+  using X::X;
+};
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -15430,10 +15430,10 @@
   CXXRecord->getDestructor());
 }
 
-if (!CXXRecord->isInvalidDecl()) {
-  // Add any implicitly-declared members to this class.
-  AddImplicitlyDeclaredMembersToClass(CXXRecord);
+// Add any implicitly-declared members to this class.
+AddImplicitlyDeclaredMembersToClass(CXXRecord);
 
+if (!CXXRecord->isInvalidDecl()) {
   // If we have virtual base classes, we may end up finding multiple
   // final overriders for a given virtual function. Check for this
   // problem now.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42810: [Sema] Add implicit members even for invalid CXXRecordDecls

2018-02-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

The following assertion from `DeclContext::removeDecl` was failing before:

  assert((D->NextInContextAndBits.getPointer() || D == LastDecl) &&
 "decl is not in decls list");


Repository:
  rC Clang

https://reviews.llvm.org/D42810



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


r323998 - PR36157: When injecting an implicit function declaration in C89, find the right

2018-02-01 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Feb  1 12:01:49 2018
New Revision: 323998

URL: http://llvm.org/viewvc/llvm-project?rev=323998&view=rev
Log:
PR36157: When injecting an implicit function declaration in C89, find the right
DeclContext rather than injecting it wherever we happen to be.

This avoids creating functions whose DeclContext is a struct or similar.

Added:
cfe/trunk/test/Sema/cxx-as-c.c
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/bitfield.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=323998&r1=323997&r2=323998&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Feb  1 12:01:49 2018
@@ -12910,10 +12910,20 @@ void Sema::ActOnFinishDelayedAttribute(S
 /// call, forming a call to an implicitly defined function (per C99 6.5.1p2).
 NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
   IdentifierInfo &II, Scope *S) {
+  // Find the scope in which the identifier is injected and the corresponding
+  // DeclContext.
+  // FIXME: C89 does not say what happens if there is no enclosing block scope.
+  // In that case, we inject the declaration into the translation unit scope
+  // instead.
   Scope *BlockScope = S;
   while (!BlockScope->isCompoundStmtScope() && BlockScope->getParent())
 BlockScope = BlockScope->getParent();
 
+  Scope *ContextScope = BlockScope;
+  while (!ContextScope->getEntity())
+ContextScope = ContextScope->getParent();
+  ContextRAII SavedContext(*this, ContextScope->getEntity());
+
   // Before we produce a declaration for an implicitly defined
   // function, see whether there was a locally-scoped declaration of
   // this name as a function or variable. If so, use that

Modified: cfe/trunk/test/Sema/bitfield.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bitfield.c?rev=323998&r1=323997&r2=323998&view=diff
==
--- cfe/trunk/test/Sema/bitfield.c (original)
+++ cfe/trunk/test/Sema/bitfield.c Thu Feb  1 12:01:49 2018
@@ -82,3 +82,7 @@ typedef __typeof__(+(t5.n--)) Unsigned;
 struct Test6 {
   : 0.0; // expected-error{{type name requires a specifier or qualifier}}
 };
+
+struct PR36157 {
+  int n : 1 ? 1 : implicitly_declare_function(); // expected-warning {{invalid 
in C99}}
+};

Added: cfe/trunk/test/Sema/cxx-as-c.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/cxx-as-c.c?rev=323998&view=auto
==
--- cfe/trunk/test/Sema/cxx-as-c.c (added)
+++ cfe/trunk/test/Sema/cxx-as-c.c Thu Feb  1 12:01:49 2018
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -verify
+
+// PR36157
+struct Foo {
+  Foo(int n) : n_(n) {} // expected-error 1+{{}} expected-warning 1+{{}}
+private:
+  int n;
+};
+int main() { Foo f; } // expected-error 1+{{}}


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


[PATCH] D42645: New simple Checker for mmap calls

2018-02-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp:62
+
+  ExplodedNode *N = C.generateErrorNode();
+  if (!N)

You should also use `generateNonFatalErrorNode()` here so that not to prevent 
the analyzer from finding other bugs on that path, because your bug doesn't 
cause abnormal program termination or otherwise leave the analyzer in an 
inconsistent state.


Repository:
  rC Clang

https://reviews.llvm.org/D42645



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


[PATCH] D42673: [RISCV] Pick the correct RISCV linker instead of calling riscv-gcc to link

2018-02-01 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang abandoned this revision.
mgrang added a comment.

For now, by setting the full triple (riscv-unknown-linux-gnu) we are able to 
invoke the correct gnu linker. So will abandon this patch.


Repository:
  rC Clang

https://reviews.llvm.org/D42673



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


[PATCH] D42457: [analyzer] Don't communicate evaluation failures through memregion hierarchy.

2018-02-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 132450.
NoQ added a comment.

Switched to plain bools and in-class initializers.


https://reviews.llvm.org/D42457

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/new.cpp

Index: test/Analysis/new.cpp
===
--- test/Analysis/new.cpp
+++ test/Analysis/new.cpp
@@ -311,8 +311,7 @@
 void testArrayDestr() {
   NoReturnDtor *p = new NoReturnDtor[2];
   delete[] p; // Calls the base destructor which aborts, checked below
-  //TODO: clang_analyzer_eval should not be called
-  clang_analyzer_eval(true); // expected-warning{{TRUE}}
+  clang_analyzer_eval(true); // no-warning
 }
 
 // Invalidate Region even in case of default destructor
Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -616,15 +616,10 @@
   Bldr.generateNode(Call.getProgramPoint(), State, Pred);
 }
 
-enum CallInlinePolicy {
-  CIP_Allowed,
-  CIP_DisallowedOnce,
-  CIP_DisallowedAlways
-};
-
-static CallInlinePolicy mayInlineCallKind(const CallEvent &Call,
-  const ExplodedNode *Pred,
-  AnalyzerOptions &Opts) {
+ExprEngine::CallInlinePolicy
+ExprEngine::mayInlineCallKind(const CallEvent &Call, const ExplodedNode *Pred,
+  AnalyzerOptions &Opts,
+  const ExprEngine::EvalCallOptions &CallOpts) {
   const LocationContext *CurLC = Pred->getLocationContext();
   const StackFrameContext *CallerSFC = CurLC->getCurrentStackFrame();
   switch (Call.getKind()) {
@@ -658,18 +653,8 @@
 // initializers for array fields in default move/copy constructors.
 // We still allow construction into ElementRegion targets when they don't
 // represent array elements.
-const MemRegion *Target = Ctor.getCXXThisVal().getAsRegion();
-if (Target && isa(Target)) {
-  if (ParentExpr)
-if (const CXXNewExpr *NewExpr = dyn_cast(ParentExpr))
-  if (NewExpr->isArray())
-return CIP_DisallowedOnce;
-
-  if (const TypedValueRegion *TR = dyn_cast(
-  cast(Target)->getSuperRegion()))
-if (TR->getValueType()->isArrayType())
-  return CIP_DisallowedOnce;
-}
+if (CallOpts.IsArrayConstructorOrDestructor)
+  return CIP_DisallowedOnce;
 
 // Inlining constructors requires including initializers in the CFG.
 const AnalysisDeclContext *ADC = CallerSFC->getAnalysisDeclContext();
@@ -688,7 +673,7 @@
 // FIXME: This is a hack. We don't handle temporary destructors
 // right now, so we shouldn't inline their constructors.
 if (CtorExpr->getConstructionKind() == CXXConstructExpr::CK_Complete)
-  if (!Target || isa(Target))
+  if (CallOpts.IsConstructorWithImproperlyModeledTargetRegion)
 return CIP_DisallowedOnce;
 
 break;
@@ -702,11 +687,8 @@
 assert(ADC->getCFGBuildOptions().AddImplicitDtors && "No CFG destructors");
 (void)ADC;
 
-const CXXDestructorCall &Dtor = cast(Call);
-
 // FIXME: We don't handle constructors or destructors for arrays properly.
-const MemRegion *Target = Dtor.getCXXThisVal().getAsRegion();
-if (Target && isa(Target))
+if (CallOpts.IsArrayConstructorOrDestructor)
   return CIP_DisallowedOnce;
 
 break;
@@ -847,7 +829,8 @@
 }
 
 bool ExprEngine::shouldInlineCall(const CallEvent &Call, const Decl *D,
-  const ExplodedNode *Pred) {
+  const ExplodedNode *Pred,
+  const EvalCallOptions &CallOpts) {
   if (!D)
 return false;
 
@@ -894,7 +877,7 @@
   // FIXME: this checks both static and dynamic properties of the call, which
   // means we're redoing a bit of work that could be cached in the function
   // summary.
-  CallInlinePolicy CIP = mayInlineCallKind(Call, Pred, Opts);
+  CallInlinePolicy CIP = mayInlineCallKind(Call, Pred, Opts, CallOpts);
   if (CIP != CIP_Allowed) {
 if (CIP == CIP_DisallowedAlways) {
   assert(!MayInline.hasValue() || MayInline.getValue());
@@ -946,7 +929,8 @@
 }
 
 void ExprEngine::defaultEvalCall(NodeBuilder &Bldr, ExplodedNode *Pred,
- const CallEvent &CallTemplate) {
+ const CallEvent &CallTemplate,
+ const EvalCallOptions &CallOpts) {
   // Make sure we have the most recent state attached to the call.
   ProgramStateRef State = Pred->getState();
   CallEventRef<> Call = CallTemplate.cloneWithState(State);
@@ -969,7 +953,7 @@
   } else {
 RuntimeDefinition RD = Call->getRuntimeDefinition();
 const Decl *D = RD.getDecl();
- 

[PATCH] D42810: [Sema] Add implicit members even for invalid CXXRecordDecls

2018-02-01 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


Repository:
  rC Clang

https://reviews.llvm.org/D42810



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


[PATCH] D42811: [CodeGen][va_args] Correct Vector Struct va-arg 'in_reg' code gen

2018-02-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: rsmith, rjmccall.

When trying to track down a different bug, we discovered
that calling `__builtin_va_arg` on a vec3f type caused
the SROA pass to issue a warning that there was an illegal
access.

Further research showed that the vec3f type is
alloca'ed as size '12', but the `_builtin_va_arg` code
on x86_64 was always loading this out of registers as 
{double, double}. Thus, the 2nd store into the vec3f
was storing in bytes 12-15!

This patch alters the original implementation which always
assumed {double, double} to use the actual coerced type 
instead, so the LLVM-IR generated is a load/GEP/store of
a <2 x float> and a float, rather than a double and a double.

Tests were added for all combinations I could think of that
would fit in 2 FP registers, and all work exactly as expected.


Repository:
  rC Clang

https://reviews.llvm.org/D42811

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/x86_64-floatvectors.c

Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -3790,17 +3790,18 @@
 Address RegAddrHi =
   CGF.Builder.CreateConstInBoundsByteGEP(RegAddrLo,
  CharUnits::fromQuantity(16));
-llvm::Type *DoubleTy = CGF.DoubleTy;
-llvm::StructType *ST = llvm::StructType::get(DoubleTy, DoubleTy);
+llvm::Type *ST = AI.canHaveCoerceToType()
+ ? AI.getCoerceToType()
+ : llvm::StructType::get(CGF.DoubleTy, CGF.DoubleTy);
 llvm::Value *V;
 Address Tmp = CGF.CreateMemTemp(Ty);
 Tmp = CGF.Builder.CreateElementBitCast(Tmp, ST);
-V = CGF.Builder.CreateLoad(
-   CGF.Builder.CreateElementBitCast(RegAddrLo, DoubleTy));
+V = CGF.Builder.CreateLoad(CGF.Builder.CreateElementBitCast(
+RegAddrLo, ST->getStructElementType(0)));
 CGF.Builder.CreateStore(V,
CGF.Builder.CreateStructGEP(Tmp, 0, CharUnits::Zero()));
-V = CGF.Builder.CreateLoad(
-   CGF.Builder.CreateElementBitCast(RegAddrHi, DoubleTy));
+V = CGF.Builder.CreateLoad(CGF.Builder.CreateElementBitCast(
+RegAddrHi, ST->getStructElementType(1)));
 CGF.Builder.CreateStore(V,
   CGF.Builder.CreateStructGEP(Tmp, 1, CharUnits::fromQuantity(8)));
 
Index: test/CodeGen/x86_64-floatvectors.c
===
--- test/CodeGen/x86_64-floatvectors.c
+++ test/CodeGen/x86_64-floatvectors.c
@@ -0,0 +1,131 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | \
+// RUN:   FileCheck %s
+
+// This test validates that the inreg branch generation for __builtin_va_arg 
+// does not exceed the alloca size of the type, which can cause the SROA pass to
+// eliminate the assignment.
+
+typedef struct { float x, y, z; } vec3f;
+
+double Vec3FTest(__builtin_va_list ap) {
+  vec3f vec = __builtin_va_arg(ap, vec3f);
+  return vec.x + vec.y + vec.z;
+}
+// CHECK: define double @Vec3FTest
+// CHECK: vaarg.in_reg:
+// CHECK: [[Vec3FLoad1:%.*]] = load <2 x float>, <2 x float>*
+// CHECK: [[Vec3FGEP1:%.*]] = getelementptr inbounds { <2 x float>, float }, { <2 x float>, float }* {{%.*}}, i32 0, i32 0
+// CHECK: store <2 x float> [[Vec3FLoad1]], <2 x float>* [[Vec3FGEP1]]
+// CHECK: [[Vec3FLoad2:%.*]] = load float, float*
+// CHECK: [[Vec3FGEP2:%.*]] = getelementptr inbounds { <2 x float>, float }, { <2 x float>, float }* {{%.*}}, i32 0, i32 1
+// CHECK: store float [[Vec3FLoad2]], float* [[Vec3FGEP2]]
+// CHECK: vaarg.in_mem:
+
+
+typedef struct { float x, y, z, q; } vec4f;
+
+double Vec4FTest(__builtin_va_list ap) {
+  vec4f vec = __builtin_va_arg(ap, vec4f);
+  return vec.x + vec.y + vec.z + vec.q;
+}
+// CHECK: define double @Vec4FTest
+// CHECK: vaarg.in_reg:
+// CHECK: [[Vec4FLoad1:%.*]] = load <2 x float>, <2 x float>*
+// CHECK: [[Vec4FGEP1:%.*]] = getelementptr inbounds { <2 x float>, <2 x float> }, { <2 x float>, <2 x float> }* {{%.*}}, i32 0, i32 0
+// CHECK: store <2 x float> [[Vec4FLoad1]], <2 x float>* [[Vec4FGEP1]]
+// CHECK: [[Vec4FLoad2:%.*]] = load <2 x float>, <2 x float>*
+// CHECK: [[Vec4FGEP2:%.*]] = getelementptr inbounds { <2 x float>, <2 x float> }, { <2 x float>, <2 x float> }* {{%.*}}, i32 0, i32 1
+// CHECK: store <2 x float> [[Vec4FLoad2]], <2 x float>* [[Vec4FGEP2]]
+// CHECK: vaarg.in_mem:
+
+typedef struct { double x, y; } vec2d;
+
+double Vec2DTest(__builtin_va_list ap) {
+  vec2d vec = __builtin_va_arg(ap, vec2d);
+  return vec.x + vec.y;
+}
+// CHECK: define double @Vec2DTest
+// CHECK: vaarg.in_reg:
+// CHECK: [[Vec2DLoad1:%.*]] = load double, double*
+// CHECK: [[Vec2DGEP1:%.*]] = getelementptr inbounds { double, double }, { double, double }* {{%.*}}, i32 0, i32 0
+// CHECK: store double [[Vec2DLoad1]], double* [[Vec2DGEP1]]
+// CHECK: [[Vec2DLoad2:%.*]] = load double, double*
+// CHECK: [[Vec2DGEP2:%.*]

[PATCH] D42812: [clang-tidy] ObjC ARC objects should not trigger performance-unnecessary-value-param

2018-02-01 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: alexfh, hokein.
Herald added subscribers: cfe-commits, xazax.hun, klimek.

The following Objective-C code currently incorrectly triggers
clang-tidy's performance-unnecessary-value-param check:

  % cat /tmp/performance-unnecessary-value-param-arc.m
  void foo(id object) { }
  
  clang-tidy /tmp/performance-unnecessary-value-param-arc.m
  -checks=-\*,performance-unnecessary-value-param -- -xobjective-c
  -fobjc-abi-version=2 -fobjc-arc
  1 warning generated.
  
/src/llvm/tools/clang/tools/extra/test/clang-tidy/performance-unnecessary-value-param-arc.m:10:13:
  warning: the parameter 'object' is copied for each invocation but only
  used as a const reference; consider making it a const reference
  [performance-unnecessary-value-param]
  void foo(id object) { }
   ~~ ^
   const &

This is wrong for a few reasons:

1. Objective-C doesn't have references, so `const &` is not going to help
2. ARC heavily optimizes the "expensive" copy which triggers the warning

This fixes the issue by disabling the warning for non-C++, as well as
disabling it for objects under ARC memory management for
Objective-C++.

Test Plan: New tests added. Ran tests with `make -j12 check-clang-tools`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42812

Files:
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tidy/utils/TypeTraits.cpp
  test/clang-tidy/performance-unnecessary-value-param-arc.m
  test/clang-tidy/performance-unnecessary-value-param-arc.mm


Index: test/clang-tidy/performance-unnecessary-value-param-arc.mm
===
--- /dev/null
+++ test/clang-tidy/performance-unnecessary-value-param-arc.mm
@@ -0,0 +1,16 @@
+// RUN: clang-tidy %s -checks=-*,performance-unnecessary-value-param -- \
+// RUN:   -xobjective-c++ -fobjc-abi-version=2 -fobjc-arc | count 0
+
+#if !__has_feature(objc_arc)
+#error Objective-C ARC not enabled as expected
+#endif
+
+// Passing an Objective-C ARC-managed object to a C function should
+// not raise performance-unnecessary-value-param.
+void foo(id object) { }
+
+// Same for explcitly non-ARC-managed Objective-C objects.
+void bar(__unsafe_unretained id object) { }
+
+// Same for Objective-c classes.
+void baz(Class c) { }
Index: test/clang-tidy/performance-unnecessary-value-param-arc.m
===
--- /dev/null
+++ test/clang-tidy/performance-unnecessary-value-param-arc.m
@@ -0,0 +1,16 @@
+// RUN: clang-tidy %s -checks=-*,performance-unnecessary-value-param -- \
+// RUN:   -xobjective-c -fobjc-abi-version=2 -fobjc-arc | count 0
+
+#if !__has_feature(objc_arc)
+#error Objective-C ARC not enabled as expected
+#endif
+
+// Passing an Objective-C ARC-managed object to a C function should
+// not raise performance-unnecessary-value-param.
+void foo(id object) { }
+
+// Same for explcitly non-ARC-managed Objective-C objects.
+void bar(__unsafe_unretained id object) { }
+
+// Same for Objective-c classes.
+void baz(Class c) { }
Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -45,7 +45,8 @@
 return llvm::None;
   return !Type.isTriviallyCopyableType(Context) &&
  !classHasTrivialCopyAndDestroy(Type) &&
- !hasDeletedCopyConstructor(Type);
+ !hasDeletedCopyConstructor(Type) &&
+ !Type->isObjCLifetimeType();
 }
 
 bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl,
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -79,6 +79,10 @@
   Options.getLocalOrGlobal("IncludeStyle", "llvm"))) {}
 
 void UnnecessaryValueParamCheck::registerMatchers(MatchFinder *Finder) {
+  // This check is specific to C++ and doesn't apply to languages like
+  // Objective-C.
+  if (!getLangOpts().CPlusPlus)
+return;
   const auto ExpensiveValueParamDecl =
   parmVarDecl(hasType(hasCanonicalType(allOf(
   unless(referenceType()), 
matchers::isExpensiveToCopy(,


Index: test/clang-tidy/performance-unnecessary-value-param-arc.mm
===
--- /dev/null
+++ test/clang-tidy/performance-unnecessary-value-param-arc.mm
@@ -0,0 +1,16 @@
+// RUN: clang-tidy %s -checks=-*,performance-unnecessary-value-param -- \
+// RUN:   -xobjective-c++ -fobjc-abi-version=2 -fobjc-arc | count 0
+
+#if !__has_feature(objc_arc)
+#error Objective-C ARC not enabled as expected
+#endif
+
+// Passing an Objective-C ARC-managed object to a C function should
+// not raise performance-unnecessary-value-param.
+void foo(id object) { }
+
+// Same for explcitly non-ARC-managed

[PATCH] D42645: New simple Checker for mmap calls

2018-02-01 Thread David CARLIER via Phabricator via cfe-commits
devnexen updated this revision to Diff 132459.

Repository:
  rC Clang

https://reviews.llvm.org/D42645

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp

Index: lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -0,0 +1,78 @@
+// MmapWriteExecChecker.cpp - Check for the prot argument -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This checker tests the 3rd argument of mmap's calls to check if
+// it is writable and executable in the same time. It's somehow
+// an optional checker since for example in JIT libraries it is pretty common.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+
+using namespace clang;
+using namespace ento;
+using llvm::APSInt;
+
+namespace {
+class MmapWriteExecChecker : public Checker {
+  CallDescription MmapFn;
+  static int ProtWrite;
+  static int ProtExec;
+  mutable std::unique_ptr BT;
+public:
+  MmapWriteExecChecker() : MmapFn("mmap") {}
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
+};
+}
+
+int MmapWriteExecChecker::ProtWrite = 0x02;
+int MmapWriteExecChecker::ProtExec  = 0x04;
+
+void MmapWriteExecChecker::checkPreCall(const CallEvent &Call,
+ CheckerContext &C) const {
+  if (Call.isCalled(MmapFn)) {
+if (Call.getNumArgs() < 3)
+  return;
+
+llvm::Triple Triple = C.getASTContext().getTargetInfo().getTriple();
+
+if (Triple.isOSGlibc())
+  ProtExec = 0x01;
+
+SVal ProtVal = Call.getArgSVal(2); 
+Optional ProtLoc = ProtVal.getAs();
+int64_t Prot = ProtLoc->getValue().getSExtValue();
+
+if ((Prot & (ProtWrite | ProtExec)) == (ProtWrite | ProtExec)) {
+  if (!BT)
+BT.reset(new BugType(this, "W^X check fails", "Write Exec prot flags set"));
+
+  ExplodedNode *N = C.generateNonFatalErrorNode();
+  if (!N)
+return;
+
+  auto Report = llvm::make_unique(
+  *BT, "Both PROT_WRITE and PROT_EXEC flags had been set. It can "
+   "leads to exploitable memory regions, overwritten with malicious code"
+ , N);
+  Report->addRange(Call.getArgSourceRange(2));
+  C.emitReport(std::move(Report));
+}
+  }
+}
+
+void ento::registerMmapWriteExecChecker(CheckerManager &mgr) {
+  mgr.registerChecker();
+}
Index: lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -49,6 +49,7 @@
   MallocChecker.cpp
   MallocOverflowSecurityChecker.cpp
   MallocSizeofChecker.cpp
+  MmapWriteExecChecker.cpp
   MisusedMovedObjectChecker.cpp
   MPI-Checker/MPIBugReporter.cpp
   MPI-Checker/MPIChecker.cpp
Index: include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -86,7 +86,7 @@
 
 // The APIModeling package is for checkers that model APIs and don't perform
 // any diagnostics. These checkers are always turned on; this package is
-// intended for API modeling that is not controlled by the target triple.
+// intended for API modeling that is not controlled by the the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, InPackage;
 
@@ -394,6 +394,10 @@
   def FloatLoopCounter : Checker<"FloatLoopCounter">,
 HelpText<"Warn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP)">,
 DescFile<"CheckSecuritySyntaxOnly.cpp">;
+
+  def MmapWriteExecChecker : Checker<"MmapWriteExec">,
+HelpText<"Check if mmap() call is not both writable and executable">,
+DescFile<"MmapWriteExecChecker.cpp">;
 }
 
 let ParentPackage = SecurityAlpha in {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42549: [CodeGen] Use the zero initializer instead of storing an all zero representation.

2018-02-01 Thread Matt Davis via Phabricator via cfe-commits
mattd added a comment.

Ping :)


https://reviews.llvm.org/D42549



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


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

2018-02-01 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added a comment.

Hi Akira, thanks for working on this!




Comment at: lib/AST/ExprConstant.cpp:1165-1173
+  auto LB = Temporaries.lower_bound(Key);
+
+  // If an element with key Key is found, reset the value and return it. This
+  // can happen if Key is part of a default argument expression.
+  if (LB != Temporaries.end() && LB->first == Key)
+return LB->second = APValue();
+

I think that the problem is more subtle than this. This static assert errors 
(previously clang would assert) when it really it should be fine.
```
constexpr const int &x(const int &p = 0) { return p; }
static_assert(&x() != &x());
```
Because default arguments are allocated on the caller side, both the calls to 
`x()` call createTemporary for the same MaterializeTemporaryExpr in the same 
CallStackFrame, when really that MTE should correspond to two distinct values. 
This patch just hides that underlying problem by recycling the value created 
during the first call during the second call.

Maybe we could have a fancier key that incorporates a node on the caller side, 
such as the CXXDefaultArgExpr as well at the MTE, and store that fancy key in 
APValue::LValueBases? That would allow us generate distinct values for these 
MTEs, and also remember what expression originated it. What do you think about 
that?

There is small discussion about this problem here: 
https://bugs.llvm.org/show_bug.cgi?id=33140


https://reviews.llvm.org/D42776



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


[PATCH] D42813: [Debug] Annotate compiler generated range-for loop variables.

2018-02-01 Thread Matt Davis via Phabricator via cfe-commits
mattd created this revision.
mattd added a reviewer: rsmith.
mattd edited the summary of this revision.

This change aims to simplify debugging by annotating the range-for loop 
artificial variables (range, begin, end) with the scope depth.


https://reviews.llvm.org/D42813

Files:
  SemaStmt.cpp


Index: SemaStmt.cpp
===
--- SemaStmt.cpp
+++ SemaStmt.cpp
@@ -2025,7 +2025,7 @@
 
 /// Build a variable declaration for a for-range statement.
 VarDecl *BuildForRangeVarDecl(Sema &SemaRef, SourceLocation Loc,
-  QualType Type, const char *Name) {
+  QualType Type, StringRef Name) {
   DeclContext *DC = SemaRef.CurContext;
   IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name);
   TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc);
@@ -2093,11 +2093,13 @@
   return StmtError();
   }
 
-  // Build  auto && __range = range-init
+  // Build  auto && __range = range-init.
+  // Assume the variables are nested in the inner scope (loop body).
+  const auto DepthStr = std::to_string(S->getDepth() >> 1);
   SourceLocation RangeLoc = Range->getLocStart();
   VarDecl *RangeVar = BuildForRangeVarDecl(*this, RangeLoc,
Context.getAutoRRefDeductType(),
-   "__range");
+   std::string("__range") + DepthStr);
   if (FinishForRangeVarDecl(*this, RangeVar, Range, RangeLoc,
 diag::err_for_range_deduction_failure)) {
 LoopVar->setInvalidDecl();
@@ -2340,10 +2342,12 @@
   return StmtError();
 
 // Build auto __begin = begin-expr, __end = end-expr.
+// Assume the variables are nested in the inner scope (loop body).
+const auto DepthStr = std::to_string(S->getDepth() >> 1);
 VarDecl *BeginVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
- "__begin");
+ std::string("__begin") + 
DepthStr);
 VarDecl *EndVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
-   "__end");
+   std::string("__end") + DepthStr);
 
 // Build begin-expr and end-expr and attach to __begin and __end variables.
 ExprResult BeginExpr, EndExpr;


Index: SemaStmt.cpp
===
--- SemaStmt.cpp
+++ SemaStmt.cpp
@@ -2025,7 +2025,7 @@
 
 /// Build a variable declaration for a for-range statement.
 VarDecl *BuildForRangeVarDecl(Sema &SemaRef, SourceLocation Loc,
-  QualType Type, const char *Name) {
+  QualType Type, StringRef Name) {
   DeclContext *DC = SemaRef.CurContext;
   IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name);
   TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc);
@@ -2093,11 +2093,13 @@
   return StmtError();
   }
 
-  // Build  auto && __range = range-init
+  // Build  auto && __range = range-init.
+  // Assume the variables are nested in the inner scope (loop body).
+  const auto DepthStr = std::to_string(S->getDepth() >> 1);
   SourceLocation RangeLoc = Range->getLocStart();
   VarDecl *RangeVar = BuildForRangeVarDecl(*this, RangeLoc,
Context.getAutoRRefDeductType(),
-   "__range");
+   std::string("__range") + DepthStr);
   if (FinishForRangeVarDecl(*this, RangeVar, Range, RangeLoc,
 diag::err_for_range_deduction_failure)) {
 LoopVar->setInvalidDecl();
@@ -2340,10 +2342,12 @@
   return StmtError();
 
 // Build auto __begin = begin-expr, __end = end-expr.
+// Assume the variables are nested in the inner scope (loop body).
+const auto DepthStr = std::to_string(S->getDepth() >> 1);
 VarDecl *BeginVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
- "__begin");
+ std::string("__begin") + DepthStr);
 VarDecl *EndVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
-   "__end");
+   std::string("__end") + DepthStr);
 
 // Build begin-expr and end-expr and attach to __begin and __end variables.
 ExprResult BeginExpr, EndExpr;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42813: [Debug] Annotate compiler generated range-for loop variables.

2018-02-01 Thread Matt Davis via Phabricator via cfe-commits
mattd updated this revision to Diff 132464.
mattd added a comment.

Updating the diff, missed a few deltas that should have been in the original 
patch.


https://reviews.llvm.org/D42813

Files:
  include/clang/Sema/Scope.h
  lib/Sema/SemaStmt.cpp
  test/CodeGenCXX/debug-for-range-scope-hints.cpp
  test/CodeGenCXX/debug-info-scope.cpp
  test/CodeGenCXX/vla.cpp

Index: test/CodeGenCXX/vla.cpp
===
--- test/CodeGenCXX/vla.cpp
+++ test/CodeGenCXX/vla.cpp
@@ -68,8 +68,8 @@
 void test2(int b) {
   // CHECK-LABEL: define void {{.*}}test2{{.*}}(i32 %b)
   int varr[b];
-  // AMD: %__end = alloca i32*, align 8, addrspace(5)
-  // AMD: [[END:%.*]] = addrspacecast i32* addrspace(5)* %__end to i32**
+  // AMD: %__end1 = alloca i32*, align 8, addrspace(5)
+  // AMD: [[END:%.*]] = addrspacecast i32* addrspace(5)* %__end1 to i32**
   // get the address of %b by checking the first store that stores it 
   //CHECK: store i32 %b, i32* [[PTR_B:%.*]]
 
@@ -86,7 +86,7 @@
   //CHECK: [[VLA_SIZEOF:%.*]] = mul nuw i64 4, [[VLA_NUM_ELEMENTS_PRE]]
   //CHECK-NEXT: [[VLA_NUM_ELEMENTS_POST:%.*]] = udiv i64 [[VLA_SIZEOF]], 4
   //CHECK-NEXT: [[VLA_END_PTR:%.*]] = getelementptr inbounds i32, i32* {{%.*}}, i64 [[VLA_NUM_ELEMENTS_POST]]
-  //X64-NEXT: store i32* [[VLA_END_PTR]], i32** %__end
+  //X64-NEXT: store i32* [[VLA_END_PTR]], i32** %__end1
   //AMD-NEXT: store i32* [[VLA_END_PTR]], i32** [[END]]
   for (int d : varr) 0;
 }
@@ -94,8 +94,8 @@
 void test3(int b, int c) {
   // CHECK-LABEL: define void {{.*}}test3{{.*}}(i32 %b, i32 %c)
   int varr[b][c];
-  // AMD: %__end = alloca i32*, align 8, addrspace(5)
-  // AMD: [[END:%.*]] = addrspacecast i32* addrspace(5)* %__end to i32**
+  // AMD: %__end1 = alloca i32*, align 8, addrspace(5)
+  // AMD: [[END:%.*]] = addrspacecast i32* addrspace(5)* %__end1 to i32**
   // get the address of %b by checking the first store that stores it 
   //CHECK: store i32 %b, i32* [[PTR_B:%.*]]
   //CHECK-NEXT: store i32 %c, i32* [[PTR_C:%.*]]
Index: test/CodeGenCXX/debug-info-scope.cpp
===
--- test/CodeGenCXX/debug-info-scope.cpp
+++ test/CodeGenCXX/debug-info-scope.cpp
@@ -58,7 +58,7 @@
   }
 
   int x[] = {1, 2};
-  // CHECK: = !DILocalVariable(name: "__range"
+  // CHECK: = !DILocalVariable(name: "__range1"
   // CHECK-SAME:   scope: [[RANGE_FOR:![0-9]*]]
   // CHECK-NOT:line:
   // CHECK-SAME:   ){{$}}
Index: test/CodeGenCXX/debug-for-range-scope-hints.cpp
===
--- test/CodeGenCXX/debug-for-range-scope-hints.cpp
+++ test/CodeGenCXX/debug-for-range-scope-hints.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+struct vec {
+  using itr = int*;
+  itr begin() { return nullptr; }
+  itr end() { return nullptr; }
+};
+
+void test() {
+  vec as, bs, cs;
+
+  for (auto a : as)
+for (auto b : bs)
+  for (auto c : cs) {
+  }
+}
+
+// CHECK: define void @_Z4testv()
+// CHECK: call void @llvm.dbg.declare(metadata %struct.vec** {{.*}}, metadata ![[RANGE1:[0-9]+]]
+// CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata ![[BEGIN1:[0-9]+]]
+// CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata ![[END1:[0-9]+]]
+// CHECK: call void @llvm.dbg.declare(metadata %struct.vec** {{.*}}, metadata ![[RANGE2:[0-9]+]]
+// CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata ![[BEGIN2:[0-9]+]]
+// CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata ![[END2:[0-9]+]]
+// CHECK: call void @llvm.dbg.declare(metadata %struct.vec** {{.*}}, metadata ![[RANGE3:[0-9]+]]
+// CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata ![[BEGIN3:[0-9]+]]
+// CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata ![[END3:[0-9]+]]
+// CHECK: ![[RANGE1]] = !DILocalVariable(name: "__range1", {{.*}}, flags: DIFlagArtificial)
+// CHECK: ![[BEGIN1]] = !DILocalVariable(name: "__begin1", {{.*}}, flags: DIFlagArtificial)
+// CHECK: ![[END1]] = !DILocalVariable(name: "__end1",  {{.*}}, flags: DIFlagArtificial)
+// CHECK: ![[RANGE2]] = !DILocalVariable(name: "__range2",  {{.*}}, flags: DIFlagArtificial)
+// CHECK: ![[BEGIN2]] = !DILocalVariable(name: "__begin2", {{.*}}, flags: DIFlagArtificial)
+// CHECK: ![[END2]] = !DILocalVariable(name: "__end2",  {{.*}}, flags: DIFlagArtificial)
+// CHECK: ![[RANGE3]] = !DILocalVariable(name: "__range3",  {{.*}}, flags: DIFlagArtificial)
+// CHECK: ![[BEGIN3]] = !DILocalVariable(name: "__begin3", {{.*}}, flags: DIFlagArtificial)
+// CHECK: ![[END3]] = !DILocalVariable(name: "__end3", {{.*}}, flags: DIFlagArtificial)
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -2025,7 +2025,7 @@
 
 /// Build a variable declaration for a for-range statement.

Re: [PATCH] D42758: Support `#pragma comment(lib, "name")` in the frontend for ELF

2018-02-01 Thread Rui Ueyama via cfe-commits
On Wed, Jan 31, 2018 at 7:23 PM, Paul Robinson via Phabricator <
revi...@reviews.llvm.org> wrote:

> probinson added a comment.
>
> In https://reviews.llvm.org/D42758#993936, @ruiu wrote:
>
> > > I also wonder which is better `#pragma comment(lib, "m")` or `#pragma
> comment(lib, "m")`.
> >
> > Sorry, I meant `#pragma comment(lib, "m")` or `#pragma comment("lib",
> "m")`.
>
>
> I can't swear to it but I don't think Microsoft invented `#pragma
> comment`.  Various IBM compilers have it, with a syntax of `#pragma comment
> (  [ , "string" ] )`.  I'm not seeing a `lib` keyword specifically
> in the IBM docs, but being a keyword would be consistent with past practice.
>

Thank you for the info. If it's a common practice, I don't see a reason to
change that.

>
> 
> Comment at: lib/Parse/ParsePragma.cpp:299
> +  getTargetInfo().getTriple().isOSBinFormatELF()) {
>  MSCommentHandler.reset(new PragmaCommentHandler(Actions));
>  PP.AddPragmaHandler(MSCommentHandler.get());
> 
> PS4's binary format is ELF, so you should be able to remove the isPS4
> predicate.
>
>
> 
> Comment at: lib/Parse/ParsePragma.cpp:382
> +  getTargetInfo().getTriple().isOSBinFormatELF()) {
>  PP.RemovePragmaHandler(MSCommentHandler.get());
>  MSCommentHandler.reset();
> 
> Don't need isPS4, as it uses ELF.
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D42758
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42641: [MinGW] Emit typeinfo locally for dllimported classes without key functions

2018-02-01 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.

This is actually consistent with what Microsoft does for dllimport classes. 
They don't have key functions, but they do import vftables when a class is 
dllimport and the constructor is inline. They never import RTTI and always emit 
it locally.

In any case, yes, this organization makes the most sense to me. Presumably GCC 
also exports its vtables so that we can import them and they don't need to be 
emitted locally, but we do need to emit RTTI locally.


https://reviews.llvm.org/D42641



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


r324018 - [analyzer] Don't communicate evaluation failures through memregion hierarchy.

2018-02-01 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Feb  1 14:17:05 2018
New Revision: 324018

URL: http://llvm.org/viewvc/llvm-project?rev=324018&view=rev
Log:
[analyzer] Don't communicate evaluation failures through memregion hierarchy.

We use CXXTempObjectRegion exclusively as a bailout value for construction
targets when we are unable to find the correct construction region.
Sometimes it works correctly, but rather accidentally than intentionally.

Now that we want to increase the amount of situations where it works correctly,
the first step is to introduce a different way of communicating our failure
to find the correct construction region. EvalCallOptions are introduced
for this purpose.

For now EvalCallOptions are communicating two kinds of problems:
- We have been completely unable to find the correct construction site.
- We have found the construction site correctly, and there's more than one of
  them (i.e. array construction which we currently don't support).

Accidentally find and fix a test in which the new approach to communicating
failures produces better results.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
cfe/trunk/test/Analysis/new.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h?rev=324018&r1=324017&r2=324018&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h Thu 
Feb  1 14:17:05 2018
@@ -567,6 +567,13 @@ public:
   const LocationContext *LCtx,
   ProgramStateRef State);
 
+  struct EvalCallOptions {
+bool IsConstructorWithImproperlyModeledTargetRegion = false;
+bool IsArrayConstructorOrDestructor = false;
+
+EvalCallOptions() {}
+  };
+
   /// Evaluate a call, running pre- and post-call checks and allowing checkers
   /// to be responsible for handling the evaluation of the call itself.
   void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
@@ -574,7 +581,9 @@ public:
 
   /// \brief Default implementation of call evaluation.
   void defaultEvalCall(NodeBuilder &B, ExplodedNode *Pred,
-   const CallEvent &Call);
+   const CallEvent &Call,
+   const EvalCallOptions &CallOpts = {});
+
 private:
   void evalLoadCommon(ExplodedNodeSet &Dst,
   const Expr *NodeEx,  /* Eventually will be a CFGStmt */
@@ -598,9 +607,23 @@ private:
   void examineStackFrames(const Decl *D, const LocationContext *LCtx,
   bool &IsRecursive, unsigned &StackDepth);
 
+  enum CallInlinePolicy {
+CIP_Allowed,
+CIP_DisallowedOnce,
+CIP_DisallowedAlways
+  };
+
+  /// \brief See if a particular call should be inlined, by only looking
+  /// at the call event and the current state of analysis.
+  CallInlinePolicy mayInlineCallKind(const CallEvent &Call,
+ const ExplodedNode *Pred,
+ AnalyzerOptions &Opts,
+ const EvalCallOptions &CallOpts);
+
   /// Checks our policies and decides weither the given call should be inlined.
   bool shouldInlineCall(const CallEvent &Call, const Decl *D,
-const ExplodedNode *Pred);
+const ExplodedNode *Pred,
+const EvalCallOptions &CallOpts = {});
 
   bool inlineCall(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
   ExplodedNode *Pred, ProgramStateRef State);
@@ -650,11 +673,11 @@ private:
 
   /// For a given constructor, look forward in the current CFG block to
   /// determine the region into which an object will be constructed by \p CE.
-  /// Returns either a field or local variable region if the object will be
-  /// directly constructed in an existing region or a temporary object region
-  /// if not.
+  /// When the lookahead fails, a temporary region is returned, and the
+  /// IsConstructorWithImproperlyModeledTargetRegion flag is set in \p 
CallOpts.
   const MemRegion *getRegionForConstructedObject(const CXXConstructExpr *CE,
- ExplodedNode *Pred);
+ ExplodedNode *Pred,
+ EvalCallOptions &CallOpts);
 
   /// Store the region returned by operator new() so that the constructor
   /// that follows it knew what location to initialize. The value should be

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprE

[PATCH] D42457: [analyzer] Don't communicate evaluation failures through memregion hierarchy.

2018-02-01 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324018: [analyzer] Don't communicate evaluation 
failures through memregion hierarchy. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42457?vs=132450&id=132473#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42457

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  cfe/trunk/test/Analysis/new.cpp

Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -567,14 +567,23 @@
   const LocationContext *LCtx,
   ProgramStateRef State);
 
+  struct EvalCallOptions {
+bool IsConstructorWithImproperlyModeledTargetRegion = false;
+bool IsArrayConstructorOrDestructor = false;
+
+EvalCallOptions() {}
+  };
+
   /// Evaluate a call, running pre- and post-call checks and allowing checkers
   /// to be responsible for handling the evaluation of the call itself.
   void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
 const CallEvent &Call);
 
   /// \brief Default implementation of call evaluation.
   void defaultEvalCall(NodeBuilder &B, ExplodedNode *Pred,
-   const CallEvent &Call);
+   const CallEvent &Call,
+   const EvalCallOptions &CallOpts = {});
+
 private:
   void evalLoadCommon(ExplodedNodeSet &Dst,
   const Expr *NodeEx,  /* Eventually will be a CFGStmt */
@@ -598,9 +607,23 @@
   void examineStackFrames(const Decl *D, const LocationContext *LCtx,
   bool &IsRecursive, unsigned &StackDepth);
 
+  enum CallInlinePolicy {
+CIP_Allowed,
+CIP_DisallowedOnce,
+CIP_DisallowedAlways
+  };
+
+  /// \brief See if a particular call should be inlined, by only looking
+  /// at the call event and the current state of analysis.
+  CallInlinePolicy mayInlineCallKind(const CallEvent &Call,
+ const ExplodedNode *Pred,
+ AnalyzerOptions &Opts,
+ const EvalCallOptions &CallOpts);
+
   /// Checks our policies and decides weither the given call should be inlined.
   bool shouldInlineCall(const CallEvent &Call, const Decl *D,
-const ExplodedNode *Pred);
+const ExplodedNode *Pred,
+const EvalCallOptions &CallOpts = {});
 
   bool inlineCall(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
   ExplodedNode *Pred, ProgramStateRef State);
@@ -650,11 +673,11 @@
 
   /// For a given constructor, look forward in the current CFG block to
   /// determine the region into which an object will be constructed by \p CE.
-  /// Returns either a field or local variable region if the object will be
-  /// directly constructed in an existing region or a temporary object region
-  /// if not.
+  /// When the lookahead fails, a temporary region is returned, and the
+  /// IsConstructorWithImproperlyModeledTargetRegion flag is set in \p CallOpts.
   const MemRegion *getRegionForConstructedObject(const CXXConstructExpr *CE,
- ExplodedNode *Pred);
+ ExplodedNode *Pred,
+ EvalCallOptions &CallOpts);
 
   /// Store the region returned by operator new() so that the constructor
   /// that follows it knew what location to initialize. The value should be
Index: cfe/trunk/test/Analysis/new.cpp
===
--- cfe/trunk/test/Analysis/new.cpp
+++ cfe/trunk/test/Analysis/new.cpp
@@ -311,8 +311,7 @@
 void testArrayDestr() {
   NoReturnDtor *p = new NoReturnDtor[2];
   delete[] p; // Calls the base destructor which aborts, checked below
-  //TODO: clang_analyzer_eval should not be called
-  clang_analyzer_eval(true); // expected-warning{{TRUE}}
+  clang_analyzer_eval(true); // no-warning
 }
 
 // Invalidate Region even in case of default destructor
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -85,28 +85,32 @@
 
 
 /// Returns a region representing the first element of a (possibly
-/// multi-dimensional) array.
+/// multi-dimensional) array, for the purposes of element construction or
+/// destruction.

[libcxx] r324020 - Make std::get_temporary_buffer respect overaligned types when possible

2018-02-01 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Feb  1 14:24:45 2018
New Revision: 324020

URL: http://llvm.org/viewvc/llvm-project?rev=324020&view=rev
Log:
Make std::get_temporary_buffer respect overaligned types when possible

Patch by Chris Kennelly!

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

Added:
libcxx/trunk/test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp
Modified:
libcxx/trunk/include/memory

Modified: libcxx/trunk/include/memory
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=324020&r1=324019&r2=324020&view=diff
==
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Thu Feb  1 14:24:45 2018
@@ -2004,7 +2004,38 @@ get_temporary_buffer(ptrdiff_t __n) _NOE
 __n = __m;
 while (__n > 0)
 {
+#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
+#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
+if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+#else
+if (std::alignment_of<_Tp>::value >
+std::alignment_of::value)
+#endif
+{
+std::align_val_t __al =
+std::align_val_t(std::alignment_of<_Tp>::value);
+__r.first = static_cast<_Tp*>(::operator new(
+__n * sizeof(_Tp), __al, nothrow));
+} else {
+__r.first = static_cast<_Tp*>(::operator new(
+__n * sizeof(_Tp), nothrow));
+}
+#else
+#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
+if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+#else
+if (std::alignment_of<_Tp>::value >
+std::alignment_of::value)
+#endif
+{
+// Since aligned operator new is unavailable, return an empty
+// buffer rather than one with invalid alignment.
+return __r;
+}
+
 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), 
nothrow));
+#endif
+
 if (__r.first)
 {
 __r.second = __n;
@@ -2017,7 +2048,23 @@ get_temporary_buffer(ptrdiff_t __n) _NOE
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY
-void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
+void return_temporary_buffer(_Tp* __p) _NOEXCEPT
+{
+#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
+#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
+if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+#else
+if (std::alignment_of<_Tp>::value >
+std::alignment_of::value)
+#endif
+{
+std::align_val_t __al = 
std::align_val_t(std::alignment_of<_Tp>::value);
+::operator delete(__p, __al);
+return;
+}
+#endif
+::operator delete(__p);
+}
 
 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
 template 

Added: 
libcxx/trunk/test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp?rev=324020&view=auto
==
--- 
libcxx/trunk/test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp 
(added)
+++ 
libcxx/trunk/test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp 
Thu Feb  1 14:24:45 2018
@@ -0,0 +1,33 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template 
+//   pair
+//   get_temporary_buffer(ptrdiff_t n);
+//
+// template 
+//   void
+//   return_temporary_buffer(T* p);
+
+#include 
+#include 
+
+struct alignas(32) A {
+int field;
+};
+
+int main()
+{
+std::pair ip = std::get_temporary_buffer(5);
+assert(!(ip.first == nullptr) ^ (ip.second == 0));
+assert(reinterpret_cast(ip.first) % alignof(A) == 0);
+std::return_temporary_buffer(ip.first);
+}


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


r324021 - [analyzer] [tests] Add an option to show the histogram of path differences between the analyzer runs

2018-02-01 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Feb  1 14:25:18 2018
New Revision: 324021

URL: http://llvm.org/viewvc/llvm-project?rev=324021&view=rev
Log:
[analyzer] [tests] Add an option to show the histogram of path differences 
between the analyzer runs

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

Modified:
cfe/trunk/utils/analyzer/CmpRuns.py

Modified: cfe/trunk/utils/analyzer/CmpRuns.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/CmpRuns.py?rev=324021&r1=324020&r2=324021&view=diff
==
--- cfe/trunk/utils/analyzer/CmpRuns.py (original)
+++ cfe/trunk/utils/analyzer/CmpRuns.py Thu Feb  1 14:25:18 2018
@@ -28,6 +28,7 @@ Usage:
 
 import os
 import plistlib
+from math import log
 
 
 # Information about analysis run:
@@ -47,6 +48,7 @@ class AnalysisDiagnostic:
 self._loc = self._data['location']
 self._report = report
 self._htmlReport = htmlReport
+self._reportSize = len(self._data['path'])
 
 def getFileName(self):
 root = self._report.run.root
@@ -61,6 +63,9 @@ class AnalysisDiagnostic:
 def getColumn(self):
 return self._loc['col']
 
+def getPathLength(self):
+return self._reportSize
+
 def getCategory(self):
 return self._data['category']
 
@@ -193,7 +198,7 @@ def cmpAnalysisDiagnostic(d):
 return d.getIssueIdentifier()
 
 
-def compareResults(A, B):
+def compareResults(A, B, opts):
 """
 compareResults - Generate a relation from diagnostics in run A to
 diagnostics in run B.
@@ -206,6 +211,9 @@ def compareResults(A, B):
 
 res = []
 
+# Map size_before -> size_after
+path_difference_data = []
+
 # Quickly eliminate equal elements.
 neqA = []
 neqB = []
@@ -217,6 +225,17 @@ def compareResults(A, B):
 a = eltsA.pop()
 b = eltsB.pop()
 if (a.getIssueIdentifier() == b.getIssueIdentifier()):
+if a.getPathLength() != b.getPathLength():
+if opts.relative_path_histogram:
+path_difference_data.append(
+float(a.getPathLength()) / b.getPathLength())
+elif opts.relative_log_path_histogram:
+path_difference_data.append(
+log(float(a.getPathLength()) / b.getPathLength()))
+elif opts.absolute_path_histogram:
+path_difference_data.append(
+a.getPathLength() - b.getPathLength())
+
 res.append((a, b, 0))
 elif a.getIssueIdentifier() > b.getIssueIdentifier():
 eltsB.append(b)
@@ -238,6 +257,12 @@ def compareResults(A, B):
 for b in neqB:
 res.append((None, b, None))
 
+if opts.relative_log_path_histogram or opts.relative_path_histogram or \
+opts.absolute_path_histogram:
+from matplotlib import pyplot
+pyplot.hist(path_difference_data, bins=100)
+pyplot.show()
+
 return res
 
 
@@ -252,7 +277,7 @@ def dumpScanBuildResultsDiff(dirA, dirB,
 else:
 auxLog = None
 
-diff = compareResults(resultsA, resultsB)
+diff = compareResults(resultsA, resultsB, opts)
 foundDiffs = 0
 totalAdded = 0
 totalRemoved = 0
@@ -314,6 +339,21 @@ def main():
   [default=None]",
   action="store", type=str, default=None,
   metavar="LOG")
+parser.add_option("--relative-path-differences-histogram",
+  action="store_true", dest="relative_path_histogram",
+  default=False,
+  help="Show histogram of relative paths differences. \
+  Requires matplotlib")
+parser.add_option("--relative-log-path-differences-histogram",
+  action="store_true", dest="relative_log_path_histogram",
+  default=False,
+  help="Show histogram of log relative paths differences. \
+  Requires matplotlib")
+parser.add_option("--absolute-path-differences-histogram",
+  action="store_true", dest="absolute_path_histogram",
+  default=False,
+  help="Show histogram of absolute paths differences. \
+  Requires matplotlib")
 (opts, args) = parser.parse_args()
 
 if len(args) != 2:


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


[PATCH] D41746: Make std::get_temporary_buffer respect overaligned types when possible

2018-02-01 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX324020: Make std::get_temporary_buffer respect overaligned 
types when possible (authored by rsmith, committed by ).

Repository:
  rCXX libc++

https://reviews.llvm.org/D41746

Files:
  include/memory
  test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp

Index: include/memory
===
--- include/memory
+++ include/memory
@@ -2004,7 +2004,38 @@
 __n = __m;
 while (__n > 0)
 {
+#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
+#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
+if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+#else
+if (std::alignment_of<_Tp>::value >
+std::alignment_of::value)
+#endif
+{
+std::align_val_t __al =
+std::align_val_t(std::alignment_of<_Tp>::value);
+__r.first = static_cast<_Tp*>(::operator new(
+__n * sizeof(_Tp), __al, nothrow));
+} else {
+__r.first = static_cast<_Tp*>(::operator new(
+__n * sizeof(_Tp), nothrow));
+}
+#else
+#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
+if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+#else
+if (std::alignment_of<_Tp>::value >
+std::alignment_of::value)
+#endif
+{
+// Since aligned operator new is unavailable, return an empty
+// buffer rather than one with invalid alignment.
+return __r;
+}
+
 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
+#endif
+
 if (__r.first)
 {
 __r.second = __n;
@@ -2017,7 +2048,23 @@
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY
-void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
+void return_temporary_buffer(_Tp* __p) _NOEXCEPT
+{
+#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
+#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
+if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+#else
+if (std::alignment_of<_Tp>::value >
+std::alignment_of::value)
+#endif
+{
+std::align_val_t __al = std::align_val_t(std::alignment_of<_Tp>::value);
+::operator delete(__p, __al);
+return;
+}
+#endif
+::operator delete(__p);
+}
 
 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
 template 
Index: test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp
===
--- test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp
+++ test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp
@@ -0,0 +1,33 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template 
+//   pair
+//   get_temporary_buffer(ptrdiff_t n);
+//
+// template 
+//   void
+//   return_temporary_buffer(T* p);
+
+#include 
+#include 
+
+struct alignas(32) A {
+int field;
+};
+
+int main()
+{
+std::pair ip = std::get_temporary_buffer(5);
+assert(!(ip.first == nullptr) ^ (ip.second == 0));
+assert(reinterpret_cast(ip.first) % alignof(A) == 0);
+std::return_temporary_buffer(ip.first);
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >