[PATCH] D76229: [clang-tidy] Added PlacementNewStorageCheck

2020-03-17 Thread Karasev Nikita via Phabricator via cfe-commits
f00kat added a comment.

In D76229#1925948 , @lebedev.ri wrote:

> In D76229#1925371 , @f00kat wrote:
>
> > In D76229#1925360 , @lebedev.ri 
> > wrote:
> >
> > > This seems to be already handled by clang static analyzer? 
> > > (`clang-analyzer-cplusplus.PlacementNew`)
> > >
> > >   :19:5: warning: Storage provided to placement new is only 2 
> > > bytes, whereas the allocated type requires 8 bytes 
> > > [clang-analyzer-cplusplus.PlacementNew]
> > >   ::new (&s1) long;
> > >   ^
> > >   :19:5: note: Storage provided to placement new is only 2 bytes, 
> > > whereas the allocated type requires 8 bytes
> > >   :64:3: warning: Storage provided to placement new is only 2 
> > > bytes, whereas the allocated type requires 8 bytes 
> > > [clang-analyzer-cplusplus.PlacementNew]
> > > ::new (buffer3) long;
> > > ^
> > >
> > >
> > > https://godbolt.org/z/9VX5WW
> >
> >
> > But it seems like not all of my tests pass on static analyzer?
>
>
> I have not really worked with static analyzer code, but assuming that those 
> cases
>  that are no longer diagnosed as compared to this clang-tidy checks *should* 
> be diagnosed
>  (i.e. diagnosing them isn't false-positive), then i'd think that static 
> analyzer check
>  simply needs some work?


Yeah. You are right. I will try to improve exist checker.
What we gonna do with this patch? Remove it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76229



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


[PATCH] D75687: [clangd] Only minimally escape text when rendering to markdown.

2020-03-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!




Comment at: clang-tools-extra/clangd/FormattedString.cpp:150
+// Not a delimiter if surrounded by space.
+return !SpaceSurrounds();
+  case '-': // Setex heading, horizontal ruler, or bullet.

kadircet wrote:
> `_` seems to behave different than `*` :(
> 
> it seems to rather depend on the spaces around the text being emphasized, i.e
> 
> ```
> foo _ bar _ foo -> no emphasis
> foo _ bar_ foo -> no emphasis
> foo _bar_ foo -> emphasis on bar
> foo_bar_ foo -> no emphasis
> ```
> 
> so this should rather be `Before.endswith(" ") && isAlpha(After)` for the 
> beginning of emphasis and the opposite for the ending.
> Not sure if there's an easy way to decide on it in isolation.
regarding this one, i suppose we'll just be escaping in some unnecessary 
cases(like the 2nd and the 4th), but still better than the current state so nvm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75687



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


[PATCH] D75446: [clang][Syntax] Handle macro arguments in spelledForExpanded

2020-03-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D75446#1924496 , @sammccall wrote:

> I think per offline discussion, this was going to have some additional docs 
> clarifying the contracts of this function, and maybe extra tests?
>
> The conclusion IIRC was that this function is designed to find the text that 
> you could replace in order to replace an AST node, so it's fairly 
> conservative (but arg expansions are fair game assuming expanded once).


Right, I just didn't get a chance to look at it again. Planning to do that once 
I've got some cycles.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75446



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


[PATCH] D74918: Add method to TargetInfo to get CPU cache line size

2020-03-17 Thread Kristof Beyls via Phabricator via cfe-commits
kristof.beyls added a comment.

In D74918#1923151 , @zoecarver wrote:

> There are a lot of different ways we could implement the feature. We may want 
> to only enable it when `-march=native`, or maybe only in the unstable ABI, 
> and maybe we want to support aligned pairs on some architectures. I think 
> that's an important discussion to have but I'm not sure _this_ patch is the 
> best place to have that discussion.
>
> Even if we don't use this patch in the implementation I think it would still 
> be a good utility to have. Here's what I suggest: I commit this, create 
> another patch to add a builtin that exposes this API, and then open a libc++ 
> patch with a _possible_ implementation. In that patch, we can discuss how we 
> should actually implement the feature and after we have a consensus I can do 
> the work to implement it. Any objections to that plan?


Discussing the implementation strategy for 
std::hardware_{constructive,destructive}_interference_size on a libc++ thread 
rather than here makes sense.
I'm afraid I don't have a good view on all the ways the API and associated 
intrinsic proposed here will or could be used in practice.
My only thought on it is that we cannot guarantee that different versions of 
LLVM will keep on reporting the same number, even for identical targets.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74918



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


[PATCH] D75851: [Analyzer][StreamChecker] Added evaluation of fseek.

2020-03-17 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:470
 
-  // Make the return value accordingly to the error.
-  State = State->assume(RetVal, (SS->*IsOfError)());
-  assert(State && "Return value should not be constrained already.");
-  C.addTransition(State);
+  if (SS->isUnknownError()) {
+llvm::SmallVector NewPossibleErrors;

NoQ wrote:
> Please explain the high-level idea behind this code. 
The higher level idea is that if a stream function fails we do not create a new 
state for every type of error (EOF and "other" error). Instead there will be an 
"unknown error" state. The description for each stream function contains what 
errors are possible after that function (`PossibleErrors`).

If it is needed to know the exact error (like here, what should `feof` return?) 
we look at the previous function to see what errors are possible after it. If 
EOF is not possible at all, the `feof` returns false. If EOF is possible and 
only one other type of error, we make a state split with EOF error and the 
other error set. If EOF and two possible other errors are possible there is 
state split again but the non-EOF state contains `UnknownError`.

In `PossibleErrors` the `NoError` state is possible. This indicates that the 
function failed (returned an error value) but the stream error flags are not 
set (can happen at `fseek`). There are 3 possible error values (EOF, "other" 
and no error), if after a `feof` there is `UnknownError` we know that the 
remaining 2 error types are possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75851



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


[clang] d3d8442 - Fix the buildbot error.

2020-03-17 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-03-17T09:49:43+01:00
New Revision: d3d844212fc96fb70f77431f0e6a70e0603b0a39

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

LOG: Fix the buildbot error.

Added: 


Modified: 
clang/lib/AST/ComputeDependence.cpp

Removed: 




diff  --git a/clang/lib/AST/ComputeDependence.cpp 
b/clang/lib/AST/ComputeDependence.cpp
index 673e651173a3..4ca4eacde8b7 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -604,8 +604,8 @@ ExprDependence 
clang::computeDependence(DependentScopeDeclRefExpr *E) {
 
 ExprDependence clang::computeDependence(CXXConstructExpr *E) {
   auto D = toExprDependence(E->getType()->getDependence());
-  for (auto *E : E->arguments())
-D |= E->getDependence() & ~ExprDependence::Type;
+  for (auto *A : E->arguments())
+D |= A->getDependence() & ~ExprDependence::Type;
   return D;
 }
 



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


[PATCH] D75034: [clang-format] use spaces for alignment with UT_ForContinuationAndIndentation

2020-03-17 Thread Maximilian Fickert via Phabricator via cfe-commits
fickert added a comment.

From the original commit, it does seem that this behavior was desired.

However, from the name of the option and description in the documentation ("Use 
tabs only for line continuation and indentation"), I would expect it to use 
tabs only for indentation and continuation, but spaces for alignment. The 
current behavior uses spaces for some types of alignment that appear in the 
middle of a line (e.g. consecutive assignments/declarations), but not for 
others that occur at the beginning of a line (e.g. function parameters). The 
bug report seems to indicate that other people also expected a different 
behavior given the description.

Does anyone else want to comment? Otherwise I can move the changed behavior 
into a new option; in that case, I'd be happy about naming suggestions.


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

https://reviews.llvm.org/D75034



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


[PATCH] D75443: [AST] Unpack FPFeatures bits to BinaryOperator, NFC.

2020-03-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein abandoned this revision.
hokein added a comment.

woo, looks like the `IsOMPStructuredBlock` bit in `Stmt` was removed in 
https://reviews.llvm.org/rGd5edcb90643104d6911da5c0ff44c4f33fff992f, we can use 
the bit for `error`, so this patch is not needed anymore.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75443



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


[PATCH] D73638: [AST] Move dependence computations into a separate file

2020-03-17 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio added inline comments.



Comment at: clang/lib/AST/ComputeDependence.cpp:607
+  auto D = toExprDependence(E->getType()->getDependence());
+  for (auto *E : E->arguments())
+D |= E->getDependence() & ~ExprDependence::Type;

I'm impressed this even compiled. With gcc 8.3 I get an error:
```
/work/bf/LLVM/src/clang/lib/AST/ComputeDependence.cpp:607:18: error: use of ‘E’ 
before deduction of ‘auto’
   for (auto *E : E->arguments())
  ^
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73638



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


[PATCH] D76125: [clangd] Decouple preambleworker from astworker, NFCI

2020-03-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 250705.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76125

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/TUScheduler.cpp

Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -49,13 +49,16 @@
 #include "GlobalCompilationDatabase.h"
 #include "Logger.h"
 #include "ParsedAST.h"
+#include "Path.h"
 #include "Preamble.h"
+#include "Threading.h"
 #include "Trace.h"
 #include "index/CanonicalIncludes.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Threading.h"
@@ -149,6 +152,176 @@
 };
 
 namespace {
+/// Responsible for building and providing access to the preamble of a TU.
+/// Processes async build requests on a dedicated thread executing run method.
+/// Unless RunSync is provided, which will build preambles on the requesting
+/// thread instead.
+class PreambleThread {
+public:
+  PreambleThread(llvm::StringRef FileName, ParsingCallbacks &Callbacks,
+ bool StorePreambleInMemory, bool RunSync)
+  : FileName(FileName), Callbacks(Callbacks),
+StoreInMemory(StorePreambleInMemory), RunSync(RunSync) {}
+
+  size_t getUsedBytes() const {
+auto Preamble = latest();
+return Preamble ? Preamble->Preamble.getSize() : 0;
+  }
+
+  /// It isn't guaranteed that each request will be built. If there are multiple
+  /// update requests while building a preamble, only the last one will be
+  /// built.
+  void update(CompilerInvocation *CI, ParseInputs PI) {
+// If compiler invocation was broken, just fail out early.
+if (!CI) {
+  TUStatus::BuildDetails Details;
+  Details.BuildFailed = true;
+  std::string TaskName = llvm::formatv("Update ({0})", PI.Version);
+  emitTUStatus({TUAction::BuildingPreamble, std::move(TaskName)}, &Details);
+  // Make sure anyone waiting for the preamble gets notified it could not be
+  // built.
+  BuiltFirst.notify();
+  return;
+}
+// Make possibly expensive copy while not holding the lock.
+Request Req = {std::make_unique(*CI), std::move(PI)};
+if (RunSync) {
+  build(std::move(Req));
+  return;
+}
+{
+  std::lock_guard Lock(Mutex);
+  assert(!Done && "Build request to PreambleWorker after stop");
+  NextReq = std::move(Req);
+}
+// Let the worker thread know there's a request, notify_one is safe as there
+// should be a single worker thread waiting on it.
+ReqCV.notify_all();
+  }
+
+  /// Blocks until at least a single request has been processed. Note that it
+  /// will unblock even after an unsuccessful build.
+  void waitForFirst() const { BuiltFirst.wait(); }
+
+  /// Returns the latest built preamble, might be null if no preamble has been
+  /// built or latest attempt resulted in a failure.
+  std::shared_ptr latest() const {
+std::lock_guard Lock(Mutex);
+return LatestBuild;
+  }
+
+  void run() {
+dlog("Starting preamble worker for {0}", FileName);
+while (true) {
+  {
+std::unique_lock Lock(Mutex);
+assert(!CurrentReq && "Already processing a request?");
+// Wait until stop is called or there is a request.
+ReqCV.wait(Lock, [this] { return NextReq || Done; });
+if (Done)
+  break;
+CurrentReq = std::move(*NextReq);
+// Reset it here, before we build the request to not overwrite any new
+// request that might arrive while we are still building this one.
+NextReq.reset();
+  }
+  // Build the preamble and let the waiters know about it.
+  build(std::move(*CurrentReq));
+}
+// We are no longer going to build any preambles, let the waiters know that.
+BuiltFirst.notify();
+dlog("Preamble worker for {0} finished", FileName);
+  }
+
+  /// Signals the run loop to exit.
+  void stop() {
+dlog("Stopping preamble worker for {0}", FileName);
+{
+  std::lock_guard Lock(Mutex);
+  Done = true;
+}
+// Let the worker thread know we've been stopped.
+ReqCV.notify_all();
+  }
+
+  bool blockUntilIdle(Deadline Timeout) const {
+std::unique_lock Lock(Mutex);
+return wait(Lock, ReqCV, Timeout, [&] { return !NextReq && !CurrentReq; });
+  }
+
+private:
+  /// Holds inputs required for building a preamble. CI is guaranteed to be
+  /// non-null.
+  struct Request {
+std::unique_ptr CI;
+ParseInputs Inputs;
+  };
+
+  bool isDone() {
+ 

[PATCH] D76125: [clangd] Decouple preambleworker from astworker, NFCI

2020-03-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 16 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:218
+PreambleRequested.wait(Lock, [this] { return PreambleReq || Done; });
+// No request means we are done.
+if (!PreambleReq)

sammccall wrote:
> Why do we rebuild the preamble if stop is requested?
it was to be consistent with astworker, but i suppose it isn't necessary as 
ASTWorker does that to make sure each LSP request gets a reply, and it can be 
done with stale preambles.

Are there any other reasons for ASTWorker to empty the queue after stop?



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:295
+std::shared_ptr OldPreamble =
+Inputs.ForceRebuild ? std::shared_ptr()
+: getLatestBuiltPreamble();

sammccall wrote:
> (nullptr should work here?)
right, it was copied over :/



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:312
+
+  mutable std::mutex Mutex;
+  bool Done = false;

sammccall wrote:
> Yikes, lots of state :-)
> I'd consider merging the two CVs - I find keeping the events separate and 
> reasoning when you need notify_one vs _all doesn't seem to pay off, may just 
> be the way I think about queues. Up to you.
i like them to be seperate as it makes naming easier :D but i agree that having 
less state also makes reasoning easier.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:600
 Inputs, CompilerInvocationDiagConsumer, &CC1Args);
+auto OldPreamble = PW.getLatestBuiltPreamble();
+PW.requestBuild(Invocation.get(), Inputs);

sammccall wrote:
> this doesn't seem correct (maybe ok in this patch because of the blocking, 
> but not in general). You're assuming the last available preamble is the one 
> that the last AST was built with.
> 
> I suppose you can't check the preamble of the current ParsedAST because it 
> might not be cached, and you nevertheless want to skip rebuild if the 
> diagnostics are going to be the same. I can't think of anything better than 
> continuing to hold the shared_ptr for PreambleForLastBuiltAST or something 
> like that.
right, this is just a "hack" to keep this change NFC.

in the follow-up patches i am planning to signal whether latest built preamble 
is reusable for a given `ParseInputs`, and also signal what the AST should be 
patched with.

diagnostics(ast) will only be built if preamble is re-usable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76125



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


[PATCH] D73638: [AST] Move dependence computations into a separate file

2020-03-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked an inline comment as done.
hokein added inline comments.



Comment at: clang/lib/AST/ComputeDependence.cpp:607
+  auto D = toExprDependence(E->getType()->getDependence());
+  for (auto *E : E->arguments())
+D |= E->getDependence() & ~ExprDependence::Type;

dnsampaio wrote:
> I'm impressed this even compiled. With gcc 8.3 I get an error:
> ```
> /work/bf/LLVM/src/clang/lib/AST/ComputeDependence.cpp:607:18: error: use of 
> ‘E’ before deduction of ‘auto’
>for (auto *E : E->arguments())
>   ^
> ```
yeah, it was compiled in clang. I saw a failure in the buildbot, fixed 
d3d844212fc96fb70f77431f0e6a70e0603b0a39.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73638



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


[PATCH] D76272: Fix memtag test.

2020-03-17 Thread Adrian Kuegel via Phabricator via cfe-commits
akuegel created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
akuegel added a reviewer: bkramer.
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

Right, we don't have names for values in release builds.


Matching %x makes the test fail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76272

Files:
  clang/test/Driver/memtag.c


Index: clang/test/Driver/memtag.c
===
--- clang/test/Driver/memtag.c
+++ clang/test/Driver/memtag.c
@@ -17,7 +17,7 @@
 int foo() { int x; use(&x); return x; }
 
 // CHECK-NO-SAFETY: define dso_local i32 @foo()
-// CHECK-NO-SAFETY: %x = alloca i32, align 4{{$}}
+// CHECK-NO-SAFETY: %{{.*}} = alloca i32, align 4{{$}}
 
 // CHECK-SAFETY: define dso_local i32 @foo()
-// CHECK-SAFETY: %x = alloca i32, align 4, !stack-safe
+// CHECK-SAFETY: %{{.*}} = alloca i32, align 4, !stack-safe


Index: clang/test/Driver/memtag.c
===
--- clang/test/Driver/memtag.c
+++ clang/test/Driver/memtag.c
@@ -17,7 +17,7 @@
 int foo() { int x; use(&x); return x; }
 
 // CHECK-NO-SAFETY: define dso_local i32 @foo()
-// CHECK-NO-SAFETY: %x = alloca i32, align 4{{$}}
+// CHECK-NO-SAFETY: %{{.*}} = alloca i32, align 4{{$}}
 
 // CHECK-SAFETY: define dso_local i32 @foo()
-// CHECK-SAFETY: %x = alloca i32, align 4, !stack-safe
+// CHECK-SAFETY: %{{.*}} = alloca i32, align 4, !stack-safe
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65591: [AST] Add a flag indicating if any subexpression had errors

2020-03-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 250708.
hokein added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65591

Files:
  clang/include/clang/AST/ASTDumperUtils.h
  clang/include/clang/AST/DependenceFlags.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp

Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -540,6 +540,7 @@
   Record.push_back(E->isValueDependent());
   Record.push_back(E->isInstantiationDependent());
   Record.push_back(E->containsUnexpandedParameterPack());
+  Record.push_back(E->containsErrors());
   Record.push_back(E->getValueKind());
   Record.push_back(E->getObjectKind());
 }
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2280,6 +2280,7 @@
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ContainsErrors
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
   //DeclRefExpr
@@ -2303,6 +2304,7 @@
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ContainsErrors
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
   //Integer Literal
@@ -2321,6 +2323,7 @@
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ContainsErrors
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
   //Character Literal
@@ -2339,6 +2342,7 @@
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ContainsErrors
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
   // CastExpr
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -106,7 +106,8 @@
 
 /// The number of record fields required for the Expr class
 /// itself.
-static const unsigned NumExprFields = NumStmtFields + 7;
+static const unsigned NumExprFields =
+NumStmtFields + ExprDependenceBits + 3;
 
 /// Read and initialize a ExplicitTemplateArgumentList structure.
 void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
@@ -517,6 +518,7 @@
   bool ValueDependent = Record.readInt();
   bool InstantiationDependent = Record.readInt();
   bool ContainsUnexpandedTemplateParameters = Record.readInt();
+  bool ContainsErrors = Record.readInt();
   auto Deps = ExprDependence::None;
   if (TypeDependent)
 Deps |= ExprDependence::Type;
@@ -526,6 +528,8 @@
 Deps |= ExprDependence::Instantiation;
   if (ContainsUnexpandedTemplateParameters)
 Deps |= ExprDependence::UnexpandedPack;
+  if (ContainsErrors)
+Deps |= ExprDependence::Error;
   E->setDependence(Deps);
 
   E->setValueKind(static_cast(Record.readInt()));
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -126,6 +126,11 @@
   if (const auto *E = dyn_cast(Node)) {
 dumpType(E->getType());
 
+if (E->containsErrors()) {
+  ColorScope Color(OS, ShowColors, ErrorsColor);
+  OS << " contains-errors";
+}
+
 {
   ColorScope Color(OS, ShowColors, ValueKindColor);
   switch (E->getValueKin

[PATCH] D75514: [Analyzer] Only add container note tags to the operations of the affected container

2020-03-17 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:726
+<< Text;
+return std::string(Out.str());
+  });

NoQ wrote:
> I suspect you can remove the explicit conversion to `std::string` given that 
> you've specified the return type explicitly.
Theoretically yes, because `llvm::StringRef` has a conversion operator for 
`std::string`. However, when compiling I get a compilation error:

```
error: could not convert `Out.llvm::raw_svector_ostream::str()` from 
`llvm::StringRef` to `std::__cxx11::string {aka 
std::__cxx11::basic_string}`
```


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

https://reviews.llvm.org/D75514



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


[PATCH] D76272: Fix memtag test.

2020-03-17 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.

Right, we don't have names for values in release builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76272



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


[clang] 5156e38 - Fix memtag test.

2020-03-17 Thread Adrian Kuegel via cfe-commits

Author: Adrian Kuegel
Date: 2020-03-17T11:06:32+01:00
New Revision: 5156e38eb1d3d0ef5bce1fc8491a05f3cfca0f89

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

LOG: Fix memtag test.

Summary: Matching %x makes the test fail.

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/test/Driver/memtag.c

Removed: 




diff  --git a/clang/test/Driver/memtag.c b/clang/test/Driver/memtag.c
index 9c548910048e..bfe453beef56 100644
--- a/clang/test/Driver/memtag.c
+++ b/clang/test/Driver/memtag.c
@@ -17,7 +17,7 @@ __attribute__((noinline)) void use(int *p) { *p = z; }
 int foo() { int x; use(&x); return x; }
 
 // CHECK-NO-SAFETY: define dso_local i32 @foo()
-// CHECK-NO-SAFETY: %x = alloca i32, align 4{{$}}
+// CHECK-NO-SAFETY: %{{.*}} = alloca i32, align 4{{$}}
 
 // CHECK-SAFETY: define dso_local i32 @foo()
-// CHECK-SAFETY: %x = alloca i32, align 4, !stack-safe
+// CHECK-SAFETY: %{{.*}} = alloca i32, align 4, !stack-safe



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


[PATCH] D76272: Fix memtag test.

2020-03-17 Thread Adrian Kuegel via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5156e38eb1d3: Fix memtag test. (authored by akuegel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76272

Files:
  clang/test/Driver/memtag.c


Index: clang/test/Driver/memtag.c
===
--- clang/test/Driver/memtag.c
+++ clang/test/Driver/memtag.c
@@ -17,7 +17,7 @@
 int foo() { int x; use(&x); return x; }
 
 // CHECK-NO-SAFETY: define dso_local i32 @foo()
-// CHECK-NO-SAFETY: %x = alloca i32, align 4{{$}}
+// CHECK-NO-SAFETY: %{{.*}} = alloca i32, align 4{{$}}
 
 // CHECK-SAFETY: define dso_local i32 @foo()
-// CHECK-SAFETY: %x = alloca i32, align 4, !stack-safe
+// CHECK-SAFETY: %{{.*}} = alloca i32, align 4, !stack-safe


Index: clang/test/Driver/memtag.c
===
--- clang/test/Driver/memtag.c
+++ clang/test/Driver/memtag.c
@@ -17,7 +17,7 @@
 int foo() { int x; use(&x); return x; }
 
 // CHECK-NO-SAFETY: define dso_local i32 @foo()
-// CHECK-NO-SAFETY: %x = alloca i32, align 4{{$}}
+// CHECK-NO-SAFETY: %{{.*}} = alloca i32, align 4{{$}}
 
 // CHECK-SAFETY: define dso_local i32 @foo()
-// CHECK-SAFETY: %x = alloca i32, align 4, !stack-safe
+// CHECK-SAFETY: %{{.*}} = alloca i32, align 4, !stack-safe
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] af64948 - [SVE][Inline-Asm] Add constraints for SVE ACLE types

2020-03-17 Thread Kerry McLaughlin via cfe-commits

Author: Kerry McLaughlin
Date: 2020-03-17T11:04:19Z
New Revision: af64948e2a050d1ef3b7fd314ed07b2a2fe402a5

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

LOG: [SVE][Inline-Asm] Add constraints for SVE ACLE types

Summary:
Adds the constraints described below to ensure that we
can tie variables of SVE ACLE types to operands in inline-asm:
 - y: SVE registers Z0-Z7
 - Upl: One of the low eight SVE predicate registers (P0-P7)
 - Upa: Full range of SVE predicate registers (P0-P15)

Reviewers: sdesmalen, huntergr, rovka, cameron.mcinally, efriedma, rengolin

Reviewed By: efriedma

Subscribers: miyuki, tschuett, rkruppe, psnobl, cfe-commits

Tags: #clang

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

Added: 
clang/test/CodeGen/aarch64-sve-inline-asm-crash.c
clang/test/CodeGen/aarch64-sve-inline-asm-datatypes.c
clang/test/CodeGen/aarch64-sve-inline-asm-negative-test.c

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGStmt.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index bd1a8834c2fa..336c7491a5cc 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -486,17 +486,29 @@ bool AArch64TargetInfo::validateAsmConstraint(
 Info.setAllowsRegister();
 return true;
   case 'U':
+if (Name[1] == 'p' && (Name[2] == 'l' || Name[2] == 'a')) {
+  // SVE predicate registers ("Upa"=P0-15, "Upl"=P0-P7)
+  Info.setAllowsRegister();
+  Name += 2;
+  return true;
+}
 // Ump: A memory address suitable for ldp/stp in SI, DI, SF and DF modes.
 // Utf: A memory address suitable for ldp/stp in TF mode.
 // Usa: An absolute symbolic address.
 // Ush: The high part (bits 32:12) of a pc-relative symbolic address.
-llvm_unreachable("FIXME: Unimplemented support for U* constraints.");
+
+// Better to return an error saying that it's an unrecognised constraint
+// even if this is a valid constraint in gcc.
+return false;
   case 'z': // Zero register, wzr or xzr
 Info.setAllowsRegister();
 return true;
   case 'x': // Floating point and SIMD registers (V0-V15)
 Info.setAllowsRegister();
 return true;
+  case 'y': // SVE registers (V0-V7)
+Info.setAllowsRegister();
+return true;
   }
   return false;
 }

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 5e78237743c9..befbf693ad8b 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -87,6 +87,21 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
 
   ArrayRef getGCCRegNames() const override;
   ArrayRef getGCCRegAliases() const override;
+
+  std::string convertConstraint(const char *&Constraint) const override {
+std::string R;
+switch (*Constraint) {
+case 'U': // Three-character constraint; add "@3" hint for later parsing.
+  R = std::string("@3") + std::string(Constraint, 3);
+  Constraint += 2;
+  break;
+default:
+  R = std::string(1, *Constraint);
+  break;
+}
+return R;
+  }
+
   bool validateAsmConstraint(const char *&Name,
  TargetInfo::ConstraintInfo &Info) const override;
   bool

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 1188ea39ba2c..ad8ebd245b93 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4496,8 +4496,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   // Update the largest vector width if any arguments have vector types.
   for (unsigned i = 0; i < IRCallArgs.size(); ++i) {
 if (auto *VT = dyn_cast(IRCallArgs[i]->getType()))
-  LargestVectorWidth = std::max((uint64_t)LargestVectorWidth,
-   
VT->getPrimitiveSizeInBits().getFixedSize());
+  LargestVectorWidth =
+  std::max((uint64_t)LargestVectorWidth,
+   VT->getPrimitiveSizeInBits().getKnownMinSize());
   }
 
   // Compute the calling convention and attributes.
@@ -4611,8 +4612,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 
   // Update largest vector width from the return type.
   if (auto *VT = dyn_cast(CI->getType()))
-LargestVectorWidth = std::max((uint64_t)LargestVectorWidth,
-  VT->getPrimitiveSizeInBits().getFixedSize());
+LargestVectorWidth =
+std::max((uint64_t)LargestVectorWidth,
+ VT->getPrimitiveSizeInBits().getKnownMinSize());
 
   // Insert instrumentation or attach profile metadata at indirect call sites.
   // For more details, see the comment before the definition o

[PATCH] D71746: Fix the "TypeError: a bytes-like object is required, not 'str'" in exploded-graph-rewriter.py on Python 3.5+

2020-03-17 Thread germyrinn via Phabricator via cfe-commits
germyrinn added a comment.
Herald added a subscriber: Charusso.

Python makes a clear distinction between bytes and strings . Bytes objects 
contain raw data — a sequence of octets — whereas strings are Unicode sequences 
. Conversion between these two types is explicit: you encode a string to get 
bytes, specifying an encoding (which defaults to UTF-8); and you decode bytes 
to get a string. Clients of these functions should be aware that such 
conversions may fail, and should consider how failures are handled.

We can convert bytes to string  
using bytes class decode() instance method, So you need to decode the bytes 
object to produce a string. In Python 3 , the default encoding is "utf-8" , so 
you can use directly:

  b"python byte to string".decode("utf-8")




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71746



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


[PATCH] D76229: [clang-tidy] Added PlacementNewStorageCheck

2020-03-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a reviewer: martong.
NoQ added a comment.
Herald added a subscriber: rnkovacs.

First of all, the static analyzer doesn't warn on everything at once; it stops 
the analysis after a fatal error (such as UB) is found, so it doesn't explore 
the execution path further. This is the reason why some tests look like they 
don't warn, but they will if you comment out the previous tests in the same 
function.

  // bad (short is aligned to 2).
  short* s6 = nullptr;
  ::new (s6) long;
  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 's6' is aligned to 2 bytes but 
allocated type 'long' is aligned to 4 bytes [cert-mem54-cpp]

Null pointer is obviously well-aligned, so this is a false positive / incorrect 
test (though for a syntactic check that focuses on a single statement it's a 
perfectly normal test).

  // bad (just check for pointer to pointer).
  short **s7;
  ::new (*s7) long;
  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 's7' is aligned to 2 bytes but 
allocated type 'long' is aligned to 4 bytes [cert-mem54-cpp]

There's another checker that warns here: `warning: Dereference of undefined 
pointer value`. So the analysis is interrupted before `new` is reached.

  // bad (buffer is aligned to 'short' instead of 'long').
  alignas(short) unsigned char buffer2[sizeof(long)];
  ::new (buffer2) long;
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'buffer2' is aligned to 2 bytes 
but allocated type 'long' is aligned to 4 bytes [cert-mem54-cpp]

Hmm, i think we don't have an insufficient alignment check yet, only an 
insufficient storage check. Same goes for all of the `test3()`. These shouldn't 
be too hard to add so that, at least, to pass the missing tests.

  short* test4_f1()
  {
  return nullptr;
  }
  
  void test4()
  {
  ::new (test4_f1()) long;
  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'test4_f1' is aligned to 2 
bytes but allocated type 'long' is aligned to 4 bytes [cert-mem54-cpp]

Again, the static analyzer is inter-procedural so it knows that it's a null 
pointer.

  short* (*p1)();
  p1 = test4_f1;
  ::new (p1()) long;
  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'p1' is aligned to 2 bytes but 
allocated type 'long' is aligned to 4 bytes [cert-mem54-cpp]

We can even see through your obfuscation via function pointer! It's still null.

  struct S
  {
  short a;
  };
  
  // bad (not enough space).
  const unsigned N = 32;
  alignas(S) unsigned char buffer1[sizeof(S) * N];
  ::new (buffer1) S[N];
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 64 bytes are not enough for array 
allocation which requires 64 bytes [cert-mem54-cpp]
  
  // maybe ok but we need to warn.
  alignas(S) unsigned char buffer2[sizeof(S) * N + sizeof(int)];
  ::new (buffer2) S[N];
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: possibly not enough 68 bytes for 
array allocation which requires 64 bytes. current overhead requires the size of 
4 bytes [cert-mem54-cpp]

Ah yes, placement array-new, we're still missing it but it shouldn't be hard to 
add.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76229



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


[PATCH] D76084: [Sema][SVE] Reject subscripts on pointers to sizeless types

2020-03-17 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG010005f0774e: [Sema][SVE] Reject subscripts on pointers to 
sizeless types (authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76084

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -163,6 +163,10 @@
   *&volatile_int8 = local_int8;
   *&const_volatile_int8 = local_int8; // expected-error {{read-only variable 
is not assignable}}
 
+  global_int8_ptr[0] = local_int8;   // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr[1] = local_int8;   // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr = &global_int8_ptr[2]; // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+
   overf(local_int8);
   overf(local_int16);
 
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -142,6 +142,10 @@
   *&volatile_int8 = local_int8;
   *&const_volatile_int8 = local_int8; // expected-error {{read-only variable 
is not assignable}}
 
+  global_int8_ptr[0] = local_int8;   // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr[1] = local_int8;   // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr = &global_int8_ptr[2]; // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+
   overf(local_int8);
   overf(local_int16);
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4885,8 +4885,9 @@
 // See IsCForbiddenLValueType.
 if (!ResultType.hasQualifiers()) VK = VK_RValue;
   } else if (!ResultType->isDependentType() &&
-  RequireCompleteType(LLoc, ResultType,
-  diag::err_subscript_incomplete_type, BaseExpr))
+ RequireCompleteSizedType(
+ LLoc, ResultType,
+ diag::err_subscript_incomplete_or_sizeless_type, BaseExpr))
 return ExprError();
 
   assert(VK == VK_RValue || LangOpts.CPlusPlus ||
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6126,8 +6126,8 @@
   "array subscript is not an integer">;
 def err_subscript_function_type : Error<
   "subscript of pointer to function type %0">;
-def err_subscript_incomplete_type : Error<
-  "subscript of pointer to incomplete type %0">;
+def err_subscript_incomplete_or_sizeless_type : Error<
+  "subscript of pointer to %select{incomplete|sizeless}0 type %1">;
 def err_dereference_incomplete_type : Error<
   "dereference of pointer to incomplete type %0">;
 def ext_gnu_subscript_void_type : Extension<


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -163,6 +163,10 @@
   *&volatile_int8 = local_int8;
   *&const_volatile_int8 = local_int8; // expected-error {{read-only variable is not assignable}}
 
+  global_int8_ptr[0] = local_int8;   // expected-error {{subscript of pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr[1] = local_int8;   // expected-error {{subscript of pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr = &global_int8_ptr[2]; // expected-error {{subscript of pointer to sizeless type 'svint8_t'}}
+
   overf(local_int8);
   overf(local_int16);
 
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -142,6 +142,10 @@
   *&volatile_int8 = local_int8;
   *&const_volatile_int8 = local_int8; // expected-error {{read-only variable is not assignable}}
 
+  global_int8_ptr[0] = local_int8;   // expected-error {{subscript of pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr[1] = local_int8;   // expected-error {{subscript of pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr = &global_int8_ptr[2]; // expected-error {{subscript of pointer to sizeless type 'svint8_t'}}
+
   overf(local_int8);
   overf(local_int16);
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4885,8 +4885,9 @@
 

[clang] 010005f - [Sema][SVE] Reject subscripts on pointers to sizeless types

2020-03-17 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-17T11:24:57Z
New Revision: 010005f0774e13475c321f78b89bdc79eb78d5a5

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

LOG: [Sema][SVE] Reject subscripts on pointers to sizeless types

clang currently accepts:

  __SVInt8_t &foo1(__SVInt8_t *x) { return *x; }
  __SVInt8_t &foo2(__SVInt8_t *x) { return x[1]; }

The first function is valid ACLE code and generates correct LLVM IR
(and assembly code).  But the second function is invalid for the
same reason that arrays of sizeless types are.  Trying to code-generate
the function leads to:

  llvm/include/llvm/Support/TypeSize.h:126: uint64_t 
llvm::TypeSize::getFixedSize() const: Assertion `!IsScalable && "Request for a 
fixed size on a s
calable object"' failed.

Another problem is that:

  template
  constexpr __SIZE_TYPE__ f(T *x) { return &x[1] - x; }
  typedef int arr1[f((int *)0) - 1];
  typedef int arr2[f((__SVInt8_t *)0) - 1];

produces:

  a.cpp:2:48: warning: subtraction of pointers to type '__SVInt8_t' of zero 
size has undefined behavior [-Wpointer-arith]
  constexpr __SIZE_TYPE__ f(T *x) { return &x[1] - x; }
   ~ ^ ~
  a.cpp:4:18: note: in instantiation of function template specialization 
'f<__SVInt8_t>' requested here
  typedef int arr2[f((__SVInt8_t *)0) - 1];

This patch reports an appropriate diagnostic instead.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/sizeless-1.c
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cc815a4993d5..4c057badbfe2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6126,8 +6126,8 @@ def err_typecheck_subscript_not_integer : Error<
   "array subscript is not an integer">;
 def err_subscript_function_type : Error<
   "subscript of pointer to function type %0">;
-def err_subscript_incomplete_type : Error<
-  "subscript of pointer to incomplete type %0">;
+def err_subscript_incomplete_or_sizeless_type : Error<
+  "subscript of pointer to %select{incomplete|sizeless}0 type %1">;
 def err_dereference_incomplete_type : Error<
   "dereference of pointer to incomplete type %0">;
 def ext_gnu_subscript_void_type : Extension<

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 546f3ac7325b..a3ac74323d59 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4885,8 +4885,9 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
 // See IsCForbiddenLValueType.
 if (!ResultType.hasQualifiers()) VK = VK_RValue;
   } else if (!ResultType->isDependentType() &&
-  RequireCompleteType(LLoc, ResultType,
-  diag::err_subscript_incomplete_type, BaseExpr))
+ RequireCompleteSizedType(
+ LLoc, ResultType,
+ diag::err_subscript_incomplete_or_sizeless_type, BaseExpr))
 return ExprError();
 
   assert(VK == VK_RValue || LangOpts.CPlusPlus ||

diff  --git a/clang/test/Sema/sizeless-1.c b/clang/test/Sema/sizeless-1.c
index 962595b7b1f8..70f9fb777cc5 100644
--- a/clang/test/Sema/sizeless-1.c
+++ b/clang/test/Sema/sizeless-1.c
@@ -142,6 +142,10 @@ void func(int sel) {
   *&volatile_int8 = local_int8;
   *&const_volatile_int8 = local_int8; // expected-error {{read-only variable 
is not assignable}}
 
+  global_int8_ptr[0] = local_int8;   // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr[1] = local_int8;   // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr = &global_int8_ptr[2]; // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+
   overf(local_int8);
   overf(local_int16);
 

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index 8b6c00f6e044..4c56784f35db 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -163,6 +163,10 @@ void func(int sel) {
   *&volatile_int8 = local_int8;
   *&const_volatile_int8 = local_int8; // expected-error {{read-only variable 
is not assignable}}
 
+  global_int8_ptr[0] = local_int8;   // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr[1] = local_int8;   // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+  global_int8_ptr = &global_int8_ptr[2]; // expected-error {{subscript of 
pointer to sizeless type 'svint8_t'}}
+
   overf(local_int8);
   overf(local_int16);
 



__

[PATCH] D75690: [SVE][Inline-Asm] Add constraints for SVE ACLE types

2020-03-17 Thread Kerry McLaughlin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf64948e2a05: [SVE][Inline-Asm] Add constraints for SVE ACLE 
types (authored by kmclaughlin).

Changed prior to commit:
  https://reviews.llvm.org/D75690?vs=249092&id=250720#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75690

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/aarch64-sve-inline-asm-crash.c
  clang/test/CodeGen/aarch64-sve-inline-asm-datatypes.c
  clang/test/CodeGen/aarch64-sve-inline-asm-negative-test.c

Index: clang/test/CodeGen/aarch64-sve-inline-asm-negative-test.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-inline-asm-negative-test.c
@@ -0,0 +1,21 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: not %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns \
+// RUN:   -target-feature +neon -S -O1 -o - %s | FileCheck %s
+
+// Assembler error
+// Output constraint : Set a vector constraint on an integer
+__SVFloat32_t funcB2()
+{
+  __SVFloat32_t ret ;
+  asm volatile (
+"fmov %[ret], wzr \n"
+: [ret] "=w" (ret)
+:
+:);
+
+  return ret ;
+}
+
+// CHECK: funcB2
+// CHECK-ERROR: error: invalid operand for instruction
Index: clang/test/CodeGen/aarch64-sve-inline-asm-datatypes.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-inline-asm-datatypes.c
@@ -0,0 +1,252 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns \
+// RUN:   -target-feature +neon -S -O1 -o - -emit-llvm %s | FileCheck %s
+
+// Tests to check that all sve datatypes can be passed in as input operands
+// and passed out as output operands.
+
+#define SVINT_TEST(DT, KIND)\
+DT func_int_##DT##KIND(DT in)\
+{\
+  DT out;\
+  asm volatile (\
+"ptrue p0.b\n"\
+"mov %[out]." #KIND ", p0/m, %[in]." #KIND "\n"\
+: [out] "=w" (out)\
+: [in] "w" (in)\
+: "p0"\
+);\
+  return out;\
+}
+
+SVINT_TEST(__SVUint8_t,b);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.b, p0/m, $1.b\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint8_t,h);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.h, p0/m, $1.h\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint8_t,s);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.s, p0/m, $1.s\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint8_t,d);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.d, p0/m, $1.d\0A", "=w,w,~{p0}"( %in)
+
+SVINT_TEST(__SVUint16_t,b);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.b, p0/m, $1.b\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint16_t,h);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.h, p0/m, $1.h\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint16_t,s);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.s, p0/m, $1.s\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint16_t,d);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.d, p0/m, $1.d\0A", "=w,w,~{p0}"( %in)
+
+SVINT_TEST(__SVUint32_t,b);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.b, p0/m, $1.b\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint32_t,h);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.h, p0/m, $1.h\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint32_t,s);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.s, p0/m, $1.s\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint32_t,d);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.d, p0/m, $1.d\0A", "=w,w,~{p0}"( %in)
+
+SVINT_TEST(__SVUint64_t,b);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.b, p0/m, $1.b\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint64_t,h);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.h, p0/m, $1.h\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint64_t,s);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.s, p0/m, $1.s\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVUint64_t,d);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.d, p0/m, $1.d\0A", "=w,w,~{p0}"( %in)
+
+SVINT_TEST(__SVInt8_t,b);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.b, p0/m, $1.b\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVInt8_t,h);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.h, p0/m, $1.h\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVInt8_t,s);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.s, p0/m, $1.s\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVInt8_t,d);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.d, p0/m, $1.d\0A", "=w,w,~{p0}"( %in)
+
+SVINT_TEST(__SVInt16_t,b);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.b, p0/m, $1.b\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVInt16_t,h);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.h, p0/m, $1.h\0A", "=w,w,~{p0}"( %in)
+SVINT_TEST(__SVInt16_t,s);
+// CHECK: call  asm sideeffect "ptrue p0.b\0Amov $0.s, p0/m, $1.s\

[clang] 94489f3 - [Sema][SVE] Reject arithmetic on pointers to sizeless types

2020-03-17 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-17T11:35:20Z
New Revision: 94489f35a7f8e16d7fd553ddf96023cb78a2afbb

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

LOG: [Sema][SVE] Reject arithmetic on pointers to sizeless types

This patch completes a trio of changes related to arrays of
sizeless types.  It rejects various forms of arithmetic on
pointers to sizeless types, in the same way as for other
incomplete types.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/sizeless-1.c
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4c057badbfe2..1d32bc547905 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6237,8 +6237,8 @@ def err_typecheck_illegal_increment_decrement : Error<
   "cannot %select{decrement|increment}1 value of type %0">;
 def err_typecheck_expect_int : Error<
   "used type %0 where integer is required">;
-def err_typecheck_arithmetic_incomplete_type : Error<
-  "arithmetic on a pointer to an incomplete type %0">;
+def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
+  "arithmetic on a pointer to %select{an incomplete|sizeless}0 type %1">;
 def err_typecheck_pointer_arith_function_type : Error<
   "arithmetic on%select{ a|}0 pointer%select{|s}0 to%select{ the|}2 "
   "function type%select{|s}2 %1%select{| and %3}2">;

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index a3ac74323d59..c1bfb962677a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9534,9 +9534,10 @@ static bool checkArithmeticIncompletePointerType(Sema 
&S, SourceLocation Loc,
 
   assert(ResType->isAnyPointerType() && !ResType->isDependentType());
   QualType PointeeTy = ResType->getPointeeType();
-  return S.RequireCompleteType(Loc, PointeeTy,
-   diag::err_typecheck_arithmetic_incomplete_type,
-   PointeeTy, Operand->getSourceRange());
+  return S.RequireCompleteSizedType(
+  Loc, PointeeTy,
+  diag::err_typecheck_arithmetic_incomplete_or_sizeless_type,
+  Operand->getSourceRange());
 }
 
 /// Check the validity of an arithmetic pointer operand.

diff  --git a/clang/test/Sema/sizeless-1.c b/clang/test/Sema/sizeless-1.c
index 70f9fb777cc5..c823823fa00c 100644
--- a/clang/test/Sema/sizeless-1.c
+++ b/clang/test/Sema/sizeless-1.c
@@ -137,6 +137,8 @@ void func(int sel) {
   dump(&volatile_int8);
   dump(&const_volatile_int8);
 
+  dump(&local_int8 + 1); // expected-error {{arithmetic on a pointer to 
sizeless type}}
+
   *&local_int8 = local_int8;
   *&const_int8 = local_int8; // expected-error {{read-only variable is not 
assignable}}
   *&volatile_int8 = local_int8;
@@ -158,6 +160,16 @@ void func(int sel) {
   noproto(local_int8);
   varargs(1, local_int8, local_int16);
 
+  global_int8_ptr++; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr--; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  ++global_int8_ptr; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  --global_int8_ptr; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr + 1;   // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr - 1;   // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr += 1;  // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr -= 1;  // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr - global_int8_ptr; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+
   +init_int8;   // expected-error {{invalid argument type 'svint8_t'}}
   ++init_int8;  // expected-error {{cannot increment value of type 
'svint8_t'}}
   init_int8++;  // expected-error {{cannot increment value of type 
'svint8_t'}}

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index 4c56784f35db..b13b862f5fab 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -158,6 +158,8 @@ void func(int sel) {
   dump(&volatile_int8);
   dump(&const_volatile_int8);
 
+  dump(&local_int8 + 1); // expected-error {{arithmetic on a pointer to 
sizeless type}}
+
   *&local_int8 = local_int8;
   *&const_int8 = local_int8; // expected-error {{read-only variable is not 
assignable}}
   *&volatile_int8 = local_

[clang] 0947296 - [Sema][SVE] Reject sizeless types in exception specs

2020-03-17 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-17T11:39:03Z
New Revision: 0947296902075aaa240d78f66aa0708f825ffb35

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

LOG: [Sema][SVE] Reject sizeless types in exception specs

In the current SVE ACLE spec, the usual rules for throwing and
catching incomplete types also apply to sizeless types.  However,
throwing pointers to sizeless types should not pose any real difficulty,
so as an extension, the clang implementation allows that.

This patch enforces these rules for explicit exception specs.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExceptionSpec.cpp
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1d32bc547905..b33e11e79604 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1537,6 +1537,9 @@ def err_distant_exception_spec : Error<
 def err_incomplete_in_exception_spec : Error<
   "%select{|pointer to |reference to }0incomplete type %1 is not allowed "
   "in exception specification">;
+def err_sizeless_in_exception_spec : Error<
+  "%select{|reference to }0sizeless type %1 is not allowed "
+  "in exception specification">;
 def ext_incomplete_in_exception_spec : 
ExtWarn,
   InGroup;
 def err_rref_in_exception_spec : Error<

diff  --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index 1e892aa622df..5c9844e1cd28 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -167,6 +167,14 @@ bool Sema::CheckSpecifiedExceptionType(QualType &T, 
SourceRange Range) {
   RequireCompleteType(Range.getBegin(), PointeeT, DiagID, Kind, Range))
 return ReturnValueOnError;
 
+  // The MSVC compatibility mode doesn't extend to sizeless types,
+  // so diagnose them separately.
+  if (PointeeT->isSizelessType() && Kind != 1) {
+Diag(Range.getBegin(), diag::err_sizeless_in_exception_spec)
+<< (Kind == 2 ? 1 : 0) << PointeeT << Range;
+return true;
+  }
+
   return false;
 }
 

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index b13b862f5fab..876f5931a7db 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -345,6 +345,12 @@ void with_default(svint8_t = svint8_t());
 constexpr int ce_taking_int8(svint8_t) { return 1; } // expected-error 
{{constexpr function's 1st parameter type 'svint8_t' (aka '__SVInt8_t') is not 
a literal type}}
 #endif
 
+#if __cplusplus < 201703L
+void throwing_func() throw(svint8_t); // expected-error {{sizeless type 
'svint8_t' (aka '__SVInt8_t') is not allowed in exception specification}}
+void throwing_pointer_func() throw(svint8_t *);
+void throwing_reference_func() throw(svint8_t &); // expected-error 
{{reference to sizeless type 'svint8_t' (aka '__SVInt8_t') is not allowed in 
exception specification}}
+#endif
+
 template 
 void template_fn_direct(T) {}
 template 



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


[clang] c47f971 - [Sema][SVE] Don't allow sizeless objects to be thrown

2020-03-17 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-17T11:52:37Z
New Revision: c47f971694be0159ffddfee8a75ae515eba91439

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

LOG: [Sema][SVE] Don't allow sizeless objects to be thrown

Summary:
The same rules for throwing and catching incomplete types also apply
to sizeless types.  This patch enforces that for throw statements.
It also make sure that we use "sizeless type" rather "incomplete type"
in the associated message.  (Both are correct, but "sizeless type" is
more specific and hopefully more user-friendly.)

The SVE ACLE simply extends the rule for incomplete types to
sizeless types.  However, throwing pointers to sizeless types
should not pose any real difficulty, so as an extension,
the clang implementation allows that.

Reviewers: sdesmalen, efriedma, rovka, rjmccall

Subscribers: tschuett, rkruppe, psnobl, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b33e11e79604..1b82abadd8a9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7120,6 +7120,8 @@ def err_throw_incomplete : Error<
   "cannot throw object of incomplete type %0">;
 def err_throw_incomplete_ptr : Error<
   "cannot throw pointer to object of incomplete type %0">;
+def err_throw_sizeless : Error<
+  "cannot throw object of sizeless type %0">;
 def warn_throw_underaligned_obj : Warning<
   "underaligned exception object thrown">,
   InGroup;

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f81aabb55e4c..5969b5abd399 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -956,6 +956,11 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc,
 E->getSourceRange()))
   return true;
 
+if (!isPointer && Ty->isSizelessType()) {
+  Diag(ThrowLoc, diag::err_throw_sizeless) << Ty << E->getSourceRange();
+  return true;
+}
+
 if (RequireNonAbstractType(ThrowLoc, ExceptionObjectTy,
diag::err_throw_abstract_type, E))
   return true;

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index 876f5931a7db..af207550eb37 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -395,6 +395,9 @@ void cxx_only(int sel) {
   local_int16 = static_cast(local_int8); // expected-error 
{{static_cast from 'svint8_t' (aka '__SVInt8_t') to 'svint16_t' (aka 
'__SVInt16_t') is not allowed}}
   sel = static_cast(local_int8);   // expected-error 
{{static_cast from 'svint8_t' (aka '__SVInt8_t') to 'int' is not allowed}}
 
+  throw local_int8; // expected-error {{cannot throw object of sizeless type 
'svint8_t'}}
+  throw global_int8_ptr;
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of 
non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a 
pseudo-destructor expression}}
 
   (void)svint8_t();



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


[clang] 72ffb16 - [Sema][SVE] Don't allow sizeless types to be caught

2020-03-17 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-17T12:00:16Z
New Revision: 72ffb16b4cde972dd3b0b5db98d1702fdcccbc6f

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

LOG: [Sema][SVE] Don't allow sizeless types to be caught

In the current SVE ACLE spec, the usual rules for throwing and
catching incomplete types also apply to sizeless types.  However,
throwing pointers to sizeless types should not pose any real difficulty,
so as an extension, the clang implementation allows that.

This patch enforces these rules for catch statements.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1b82abadd8a9..3e0591bc2cf0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7015,6 +7015,8 @@ def err_catch_incomplete_ptr : Error<
 def err_catch_incomplete_ref : Error<
   "cannot catch reference to incomplete type %0">;
 def err_catch_incomplete : Error<"cannot catch incomplete type %0">;
+def err_catch_sizeless : Error<
+  "cannot catch %select{|reference to }0sizeless type %1">;
 def err_catch_rvalue_ref : Error<"cannot catch exceptions by rvalue 
reference">;
 def err_catch_variably_modified : Error<
   "cannot catch variably modified type %0">;

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 4ffa84604fbb..2cc770e5f3d1 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -15564,6 +15564,11 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S,
   !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK))
 Invalid = true;
 
+  if (!Invalid && Mode != 1 && BaseType->isSizelessType()) {
+Diag(Loc, diag::err_catch_sizeless) << (Mode == 2 ? 1 : 0) << BaseType;
+Invalid = true;
+  }
+
   if (!Invalid && !ExDeclType->isDependentType() &&
   RequireNonAbstractType(Loc, ExDeclType,
  diag::err_abstract_type_in_decl,

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index af207550eb37..3b0b73a26eed 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -398,6 +398,19 @@ void cxx_only(int sel) {
   throw local_int8; // expected-error {{cannot throw object of sizeless type 
'svint8_t'}}
   throw global_int8_ptr;
 
+  try {
+  } catch (int) {
+  }
+  try {
+  } catch (svint8_t) { // expected-error {{cannot catch sizeless type 
'svint8_t'}}
+  }
+  try {
+  } catch (svint8_t *) {
+  }
+  try {
+  } catch (svint8_t &) { // expected-error {{cannot catch reference to 
sizeless type 'svint8_t'}}
+  }
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of 
non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a 
pseudo-destructor expression}}
 
   (void)svint8_t();



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


[PATCH] D73245: Depend stddef.h to provide max_align_t for C++11 and provide better fallback in

2020-03-17 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added inline comments.



Comment at: libcxx/include/new:240
   return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
+#elif defined(_LIBCPP_CXX03_LANG)
+  return __align > alignment_of<__libcpp_max_align_t>::value;

ldionne wrote:
> joerg wrote:
> > ldionne wrote:
> > > So, IIUC what you're saying, `__STDCPP_DEFAULT_NEW_ALIGNMENT__` is 
> > > provided by recent Clangs in C++03 mode? I tested it and it does seem to 
> > > be correct. (side note: I tend to think we should be more aggressive to 
> > > remove old compiler support, since most people don't upgrade their stdlib 
> > > without upgrading their compiler anyway).
> > > 
> > > So if we don't care about supporting old compilers that don't provide 
> > > that macro, we could just get rid of this `#elif`, and such compilers 
> > > would error out when trying to use `max_align_t` in the `#else` below. 
> > > That appears reasonable to me.
> > > 
> > > We'd still leave the `#if TEST_STD_VER >= 11` in the tests below, since 
> > > in C++03 we wouldn't provide `std::max_align_t`, however testing that we 
> > > use overaligned new in the same conditions in C++03 and C++11 becomes 
> > > trivial, because it's the same code path.
> > > 
> > > Did I get what you meant correctly? If so, that sounds like a viable path 
> > > forward to me, since we're simplifying the code. We're also improving on 
> > > our C++03 conformance, which isn't considered good but is certainly not 
> > > considered bad either.
> > Correct, it has been provided since clang 4.0 at least it seems. For 
> > testing, we have two cases, some that specifically check properties of 
> > max_align_t and those should be restricted to C++11 and newer. I think we 
> > should grow a new check that max_align_t <= 
> > __STDCPP_DEFAULT_NEW_ALIGNMENT__ as sanity check, but that's slightly OT. 
> > Most of the existing cases to check for overalignment already use 
> > __STDCPP_DEFAULT_NEW_ALIGNMENT__ anyway, so it would be a case-by-case 
> > check for those.
> I'm fine with that direction if you're willing to update the patch. I'll 
> review it.
Do I understand it correctly that instead of `__libcpp_max_align_t` (or 
(over)exposed `max_align_t`) we can rely entirely on 
`__STDCPP_DEFAULT_NEW_ALIGNMENT__`?


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

https://reviews.llvm.org/D73245



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


[PATCH] D76090: [Sema][SVE] Don't allow sizeless types to be caught

2020-03-17 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72ffb16b4cde: [Sema][SVE] Don't allow sizeless types to 
be caught (authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76090

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -398,6 +398,19 @@
   throw local_int8; // expected-error {{cannot throw object of sizeless type 
'svint8_t'}}
   throw global_int8_ptr;
 
+  try {
+  } catch (int) {
+  }
+  try {
+  } catch (svint8_t) { // expected-error {{cannot catch sizeless type 
'svint8_t'}}
+  }
+  try {
+  } catch (svint8_t *) {
+  }
+  try {
+  } catch (svint8_t &) { // expected-error {{cannot catch reference to 
sizeless type 'svint8_t'}}
+  }
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of 
non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a 
pseudo-destructor expression}}
 
   (void)svint8_t();
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15564,6 +15564,11 @@
   !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK))
 Invalid = true;
 
+  if (!Invalid && Mode != 1 && BaseType->isSizelessType()) {
+Diag(Loc, diag::err_catch_sizeless) << (Mode == 2 ? 1 : 0) << BaseType;
+Invalid = true;
+  }
+
   if (!Invalid && !ExDeclType->isDependentType() &&
   RequireNonAbstractType(Loc, ExDeclType,
  diag::err_abstract_type_in_decl,
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7015,6 +7015,8 @@
 def err_catch_incomplete_ref : Error<
   "cannot catch reference to incomplete type %0">;
 def err_catch_incomplete : Error<"cannot catch incomplete type %0">;
+def err_catch_sizeless : Error<
+  "cannot catch %select{|reference to }0sizeless type %1">;
 def err_catch_rvalue_ref : Error<"cannot catch exceptions by rvalue 
reference">;
 def err_catch_variably_modified : Error<
   "cannot catch variably modified type %0">;


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -398,6 +398,19 @@
   throw local_int8; // expected-error {{cannot throw object of sizeless type 'svint8_t'}}
   throw global_int8_ptr;
 
+  try {
+  } catch (int) {
+  }
+  try {
+  } catch (svint8_t) { // expected-error {{cannot catch sizeless type 'svint8_t'}}
+  }
+  try {
+  } catch (svint8_t *) {
+  }
+  try {
+  } catch (svint8_t &) { // expected-error {{cannot catch reference to sizeless type 'svint8_t'}}
+  }
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a pseudo-destructor expression}}
 
   (void)svint8_t();
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15564,6 +15564,11 @@
   !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK))
 Invalid = true;
 
+  if (!Invalid && Mode != 1 && BaseType->isSizelessType()) {
+Diag(Loc, diag::err_catch_sizeless) << (Mode == 2 ? 1 : 0) << BaseType;
+Invalid = true;
+  }
+
   if (!Invalid && !ExDeclType->isDependentType() &&
   RequireNonAbstractType(Loc, ExDeclType,
  diag::err_abstract_type_in_decl,
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7015,6 +7015,8 @@
 def err_catch_incomplete_ref : Error<
   "cannot catch reference to incomplete type %0">;
 def err_catch_incomplete : Error<"cannot catch incomplete type %0">;
+def err_catch_sizeless : Error<
+  "cannot catch %select{|reference to }0sizeless type %1">;
 def err_catch_rvalue_ref : Error<"cannot catch exceptions by rvalue reference">;
 def err_catch_variably_modified : Error<
   "cannot catch variably modified type %0">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D74615: [Analyzer] Add visitor to track iterator invalidation

2020-03-17 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In D74615#1923710 , @NoQ wrote:

> In D74615#1917289 , @Szelethus wrote:
>
> > You may have explained it in the summary, and I didn't get it, but why 
> > isn't putting a `NoteTag` in `invalidateAllIteratorPositions` sufficient? 
> > We could state something like `All iterators associated with 'V' are 
> > invalidated`.
>
>
> +1, that's the intended approach. I suspect we don't even need to simplify 
> the message.


That is planned (a third patch for Container Note Tags), but does not fully 
solve the problem. There could be multiple operations for the same container 
which invalidates //some// iterators. Each operation creates a not tag which 
explains the kind of iterators invalidated (e.g. all iterators after the 
iterator passed in the parameter). However that does not explain which 
operation invalidates the particular iterator which is accessed.

Generally, I do not think the note tags should completely replace custom 
visitors. Instead we should take the approach which is more convenient in each 
case. The basic rule I can think of is the following: if the checker //does// 
something with a value when adding a new transition then we should assign a 
note tag to that transition. However, if something //happens// to the value in 
a transition which is done by another checker (or the core engine) then we 
should use a visitor to find that transition.

In this case the container modeling shrinks and extends the container and 
invalidates groups of iterators. However, from the point of view of an iterator 
the invalidation happens in another checker (`ContainerModeling`). Therefore I 
still think that a visitor is needed to mark the point where that particular 
iterator was invalidated. This may result in double notes like `All iterators 
of ``V`` after ``i1`` are invalidated.` and then the next is `Iterator ``i0`` 
is invalidated.` but this is not disturbing. We already have such double notes: 
`Assuming the condition is ``true``.` then `Taking ``true``branch.`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D74615



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


[PATCH] D76088: [Sema][SVE] Don't allow sizeless objects to be thrown

2020-03-17 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc47f971694be: [Sema][SVE] Don't allow sizeless objects 
to be thrown (authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76088

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -395,6 +395,9 @@
   local_int16 = static_cast(local_int8); // expected-error 
{{static_cast from 'svint8_t' (aka '__SVInt8_t') to 'svint16_t' (aka 
'__SVInt16_t') is not allowed}}
   sel = static_cast(local_int8);   // expected-error 
{{static_cast from 'svint8_t' (aka '__SVInt8_t') to 'int' is not allowed}}
 
+  throw local_int8; // expected-error {{cannot throw object of sizeless type 
'svint8_t'}}
+  throw global_int8_ptr;
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of 
non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a 
pseudo-destructor expression}}
 
   (void)svint8_t();
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -956,6 +956,11 @@
 E->getSourceRange()))
   return true;
 
+if (!isPointer && Ty->isSizelessType()) {
+  Diag(ThrowLoc, diag::err_throw_sizeless) << Ty << E->getSourceRange();
+  return true;
+}
+
 if (RequireNonAbstractType(ThrowLoc, ExceptionObjectTy,
diag::err_throw_abstract_type, E))
   return true;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7120,6 +7120,8 @@
   "cannot throw object of incomplete type %0">;
 def err_throw_incomplete_ptr : Error<
   "cannot throw pointer to object of incomplete type %0">;
+def err_throw_sizeless : Error<
+  "cannot throw object of sizeless type %0">;
 def warn_throw_underaligned_obj : Warning<
   "underaligned exception object thrown">,
   InGroup;


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -395,6 +395,9 @@
   local_int16 = static_cast(local_int8); // expected-error {{static_cast from 'svint8_t' (aka '__SVInt8_t') to 'svint16_t' (aka '__SVInt16_t') is not allowed}}
   sel = static_cast(local_int8);   // expected-error {{static_cast from 'svint8_t' (aka '__SVInt8_t') to 'int' is not allowed}}
 
+  throw local_int8; // expected-error {{cannot throw object of sizeless type 'svint8_t'}}
+  throw global_int8_ptr;
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a pseudo-destructor expression}}
 
   (void)svint8_t();
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -956,6 +956,11 @@
 E->getSourceRange()))
   return true;
 
+if (!isPointer && Ty->isSizelessType()) {
+  Diag(ThrowLoc, diag::err_throw_sizeless) << Ty << E->getSourceRange();
+  return true;
+}
+
 if (RequireNonAbstractType(ThrowLoc, ExceptionObjectTy,
diag::err_throw_abstract_type, E))
   return true;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7120,6 +7120,8 @@
   "cannot throw object of incomplete type %0">;
 def err_throw_incomplete_ptr : Error<
   "cannot throw pointer to object of incomplete type %0">;
+def err_throw_sizeless : Error<
+  "cannot throw object of sizeless type %0">;
 def warn_throw_underaligned_obj : Warning<
   "underaligned exception object thrown">,
   InGroup;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76087: [Sema][SVE] Reject sizeless types in exception specs

2020-03-17 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG094729690207: [Sema][SVE] Reject sizeless types in exception 
specs (authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76087

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -345,6 +345,12 @@
 constexpr int ce_taking_int8(svint8_t) { return 1; } // expected-error 
{{constexpr function's 1st parameter type 'svint8_t' (aka '__SVInt8_t') is not 
a literal type}}
 #endif
 
+#if __cplusplus < 201703L
+void throwing_func() throw(svint8_t); // expected-error {{sizeless type 
'svint8_t' (aka '__SVInt8_t') is not allowed in exception specification}}
+void throwing_pointer_func() throw(svint8_t *);
+void throwing_reference_func() throw(svint8_t &); // expected-error 
{{reference to sizeless type 'svint8_t' (aka '__SVInt8_t') is not allowed in 
exception specification}}
+#endif
+
 template 
 void template_fn_direct(T) {}
 template 
Index: clang/lib/Sema/SemaExceptionSpec.cpp
===
--- clang/lib/Sema/SemaExceptionSpec.cpp
+++ clang/lib/Sema/SemaExceptionSpec.cpp
@@ -167,6 +167,14 @@
   RequireCompleteType(Range.getBegin(), PointeeT, DiagID, Kind, Range))
 return ReturnValueOnError;
 
+  // The MSVC compatibility mode doesn't extend to sizeless types,
+  // so diagnose them separately.
+  if (PointeeT->isSizelessType() && Kind != 1) {
+Diag(Range.getBegin(), diag::err_sizeless_in_exception_spec)
+<< (Kind == 2 ? 1 : 0) << PointeeT << Range;
+return true;
+  }
+
   return false;
 }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1537,6 +1537,9 @@
 def err_incomplete_in_exception_spec : Error<
   "%select{|pointer to |reference to }0incomplete type %1 is not allowed "
   "in exception specification">;
+def err_sizeless_in_exception_spec : Error<
+  "%select{|reference to }0sizeless type %1 is not allowed "
+  "in exception specification">;
 def ext_incomplete_in_exception_spec : 
ExtWarn,
   InGroup;
 def err_rref_in_exception_spec : Error<


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -345,6 +345,12 @@
 constexpr int ce_taking_int8(svint8_t) { return 1; } // expected-error {{constexpr function's 1st parameter type 'svint8_t' (aka '__SVInt8_t') is not a literal type}}
 #endif
 
+#if __cplusplus < 201703L
+void throwing_func() throw(svint8_t); // expected-error {{sizeless type 'svint8_t' (aka '__SVInt8_t') is not allowed in exception specification}}
+void throwing_pointer_func() throw(svint8_t *);
+void throwing_reference_func() throw(svint8_t &); // expected-error {{reference to sizeless type 'svint8_t' (aka '__SVInt8_t') is not allowed in exception specification}}
+#endif
+
 template 
 void template_fn_direct(T) {}
 template 
Index: clang/lib/Sema/SemaExceptionSpec.cpp
===
--- clang/lib/Sema/SemaExceptionSpec.cpp
+++ clang/lib/Sema/SemaExceptionSpec.cpp
@@ -167,6 +167,14 @@
   RequireCompleteType(Range.getBegin(), PointeeT, DiagID, Kind, Range))
 return ReturnValueOnError;
 
+  // The MSVC compatibility mode doesn't extend to sizeless types,
+  // so diagnose them separately.
+  if (PointeeT->isSizelessType() && Kind != 1) {
+Diag(Range.getBegin(), diag::err_sizeless_in_exception_spec)
+<< (Kind == 2 ? 1 : 0) << PointeeT << Range;
+return true;
+  }
+
   return false;
 }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1537,6 +1537,9 @@
 def err_incomplete_in_exception_spec : Error<
   "%select{|pointer to |reference to }0incomplete type %1 is not allowed "
   "in exception specification">;
+def err_sizeless_in_exception_spec : Error<
+  "%select{|reference to }0sizeless type %1 is not allowed "
+  "in exception specification">;
 def ext_incomplete_in_exception_spec : ExtWarn,
   InGroup;
 def err_rref_in_exception_spec : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76086: [Sema][SVE] Reject arithmetic on pointers to sizeless types

2020-03-17 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG94489f35a7f8: [Sema][SVE] Reject arithmetic on pointers to 
sizeless types (authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76086

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -158,6 +158,8 @@
   dump(&volatile_int8);
   dump(&const_volatile_int8);
 
+  dump(&local_int8 + 1); // expected-error {{arithmetic on a pointer to 
sizeless type}}
+
   *&local_int8 = local_int8;
   *&const_int8 = local_int8; // expected-error {{read-only variable is not 
assignable}}
   *&volatile_int8 = local_int8;
@@ -178,6 +180,16 @@
 
   varargs(1, local_int8, local_int16);
 
+  global_int8_ptr++; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr--; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  ++global_int8_ptr; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  --global_int8_ptr; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr + 1;   // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr - 1;   // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr += 1;  // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr -= 1;  // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr - global_int8_ptr; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+
   +init_int8;   // expected-error {{invalid argument type 'svint8_t'}}
   ++init_int8;  // expected-error {{cannot increment value of type 
'svint8_t'}}
   init_int8++;  // expected-error {{cannot increment value of type 
'svint8_t'}}
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -137,6 +137,8 @@
   dump(&volatile_int8);
   dump(&const_volatile_int8);
 
+  dump(&local_int8 + 1); // expected-error {{arithmetic on a pointer to 
sizeless type}}
+
   *&local_int8 = local_int8;
   *&const_int8 = local_int8; // expected-error {{read-only variable is not 
assignable}}
   *&volatile_int8 = local_int8;
@@ -158,6 +160,16 @@
   noproto(local_int8);
   varargs(1, local_int8, local_int16);
 
+  global_int8_ptr++; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr--; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  ++global_int8_ptr; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  --global_int8_ptr; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr + 1;   // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr - 1;   // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr += 1;  // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr -= 1;  // expected-error {{arithmetic on a 
pointer to sizeless type}}
+  global_int8_ptr - global_int8_ptr; // expected-error {{arithmetic on a 
pointer to sizeless type}}
+
   +init_int8;   // expected-error {{invalid argument type 'svint8_t'}}
   ++init_int8;  // expected-error {{cannot increment value of type 
'svint8_t'}}
   init_int8++;  // expected-error {{cannot increment value of type 
'svint8_t'}}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -9534,9 +9534,10 @@
 
   assert(ResType->isAnyPointerType() && !ResType->isDependentType());
   QualType PointeeTy = ResType->getPointeeType();
-  return S.RequireCompleteType(Loc, PointeeTy,
-   diag::err_typecheck_arithmetic_incomplete_type,
-   PointeeTy, Operand->getSourceRange());
+  return S.RequireCompleteSizedType(
+  Loc, PointeeTy,
+  diag::err_typecheck_arithmetic_incomplete_or_sizeless_type,
+  Operand->getSourceRange());
 }
 
 /// Check the validity of an arithmetic pointer operand.
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6237,8 +6237,8 @@
   "cannot %select{decremen

[clang] 4add249 - [AVR] Add support for the -mdouble=x flag

2020-03-17 Thread Ayke van Laethem via cfe-commits

Author: Ayke van Laethem
Date: 2020-03-17T13:21:03+01:00
New Revision: 4add24920550beeaed15b24e6427154a58b02e50

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

LOG: [AVR] Add support for the -mdouble=x flag

This flag is used by avr-gcc (starting with v10) to set the width of the
double type. The double type is by default interpreted as a 32-bit
floating point number in avr-gcc instead of a 64-bit floating point
number as is common on other architectures. Starting with GCC 10, a new
option has been added to control this behavior:
https://gcc.gnu.org/wiki/avr-gcc#Deviations_from_the_Standard

This commit keeps the default double at 32 bits but adds support for the
-mdouble flag (-mdouble=32 and -mdouble=64) to control this behavior.

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

Added: 
clang/test/CodeGen/mdouble.c
clang/test/Driver/mdouble.c

Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/TargetInfo.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 53b87b737568..4ba8c766269c 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -176,6 +176,7 @@ VALUE_LANGOPT(PackStruct  , 32, 0,
 VALUE_LANGOPT(MaxTypeAlign  , 32, 0,
   "default maximum alignment for types")
 VALUE_LANGOPT(AlignDouble, 1, 0, "Controls if doubles should be 
aligned to 8 bytes (x86 only)")
+VALUE_LANGOPT(DoubleSize, 32, 0, "width of double")
 VALUE_LANGOPT(LongDoubleSize, 32, 0, "width of long double")
 LANGOPT(PPCIEEELongDouble, 1, 0, "use IEEE 754 quadruple-precision 
for long double")
 COMPATIBLE_VALUE_LANGOPT(PICLevel, 2, 0, "__PIC__ level")

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bdcd771ff713..3a4830c84483 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2179,6 +2179,8 @@ def mbranches_within_32B_boundaries : Flag<["-"], 
"mbranches-within-32B-boundari
 def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, 
Group;
 def mlong_calls : Flag<["-"], "mlong-calls">, Group,
   HelpText<"Generate branches with extended addressability, usually via 
indirect jumps.">;
+def mdouble_EQ : Joined<["-"], "mdouble=">, Group, Values<"32,64">, 
Flags<[CC1Option]>,
+  HelpText<"Force double to be 32 bits or 64 bits">;
 def LongDouble_Group : OptionGroup<"">, Group,
   DocName<"Long double flags">,
   DocBrief<[{Selects the long double implementation}]>;

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 58d018c5bd3e..2330339bedfb 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -380,6 +380,20 @@ void TargetInfo::adjust(LangOptions &Opts) {
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
   }
 
+  if (Opts.DoubleSize) {
+if (Opts.DoubleSize == 32) {
+  DoubleWidth = 32;
+  LongDoubleWidth = 32;
+  DoubleFormat = &llvm::APFloat::IEEEsingle();
+  LongDoubleFormat = &llvm::APFloat::IEEEsingle();
+} else if (Opts.DoubleSize == 64) {
+  DoubleWidth = 64;
+  LongDoubleWidth = 64;
+  DoubleFormat = &llvm::APFloat::IEEEdouble();
+  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
+}
+  }
+
   if (Opts.LongDoubleSize) {
 if (Opts.LongDoubleSize == DoubleWidth) {
   LongDoubleWidth = DoubleWidth;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index cb993e75b88c..1193dde5a679 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4580,6 +4580,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   RenderFloatingPointOptions(TC, D, OFastEnabled, Args, CmdArgs,
  JA.getOffloadingDeviceKind());
 
+  if (Arg *A = Args.getLastArg(options::OPT_mdouble_EQ)) {
+if (TC.getArch() == llvm::Triple::avr)
+  A->render(Args, CmdArgs);
+else
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getAsString(Args) << TripleStr;
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
 if (TC.getTriple().isX86())
   A->render(Args, CmdArgs);

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 08a0b9831e0c..e2b24f0cfcea 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2937,6 +2937,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   Opts.PackStruct

[clang] 506406c - [Sema][SVE] Reject "new" with sizeless types

2020-03-17 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-17T12:23:46Z
New Revision: 506406c4d59267497d4ac358b49e32b4d2f72119

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

LOG: [Sema][SVE] Reject "new" with sizeless types

new-expressions for a type T require sizeof(T) to be computable,
so the SVE ACLE does not allow them for sizeless types.  At the moment:

  auto f() { return new __SVInt8_t; }

creates a call to operator new with a zero size:

  %call = call noalias nonnull i8* @_Znwm(i64 0)

This patch reports an appropriate error instead.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3e0591bc2cf0..77df05fbaf05 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6897,8 +6897,8 @@ def err_array_new_needs_size : Error<
   "array size must be specified in new expression with no initializer">;
 def err_bad_new_type : Error<
   "cannot allocate %select{function|reference}1 type %0 with new">;
-def err_new_incomplete_type : Error<
-  "allocation of incomplete type %0">;
+def err_new_incomplete_or_sizeless_type : Error<
+  "allocation of %select{incomplete|sizeless}0 type %1">;
 def err_new_array_nonconst : Error<
   "only the first dimension of an allocated array may have dynamic size">;
 def err_new_array_size_unknown_from_init : Error<

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5969b5abd399..f50e5ea02c86 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2340,7 +2340,8 @@ bool Sema::CheckAllocatedType(QualType AllocType, 
SourceLocation Loc,
 return Diag(Loc, diag::err_bad_new_type)
   << AllocType << 1 << R;
   else if (!AllocType->isDependentType() &&
-   RequireCompleteType(Loc, AllocType, 
diag::err_new_incomplete_type,R))
+   RequireCompleteSizedType(
+   Loc, AllocType, diag::err_new_incomplete_or_sizeless_type, R))
 return true;
   else if (RequireNonAbstractType(Loc, AllocType,
   diag::err_allocation_of_abstract_type))

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index 3b0b73a26eed..40fa436dd1de 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -411,6 +411,15 @@ void cxx_only(int sel) {
   } catch (svint8_t &) { // expected-error {{cannot catch reference to 
sizeless type 'svint8_t'}}
   }
 
+  new svint8_t; // expected-error {{allocation of sizeless type 
'svint8_t'}}
+  new svint8_t();   // expected-error {{allocation of sizeless type 
'svint8_t'}}
+  new svint8_t[10]; // expected-error {{allocation of sizeless type 
'svint8_t'}}
+  new svint8_t *;
+
+  new (global_int8_ptr) svint8_t; // expected-error {{allocation of 
sizeless type 'svint8_t'}}
+  new (global_int8_ptr) svint8_t();   // expected-error {{allocation of 
sizeless type 'svint8_t'}}
+  new (global_int8_ptr) svint8_t[10]; // expected-error {{allocation of 
sizeless type 'svint8_t'}}
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of 
non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a 
pseudo-destructor expression}}
 
   (void)svint8_t();



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


[clang] c6b8484 - [analyzer] StdLibraryFunctionsChecker refactor w/ inheritance

2020-03-17 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-03-17T13:25:32+01:00
New Revision: c6b8484e855bffb0a7da487cd715cef774a46fb1

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

LOG: [analyzer] StdLibraryFunctionsChecker refactor w/ inheritance

Summary:
Currently, ValueRange is very hard to extend with new kind of constraints.
For instance, it forcibly encapsulates relations between arguments and the
return value (ComparesToArgument) besides handling the regular value
ranges (OutOfRange, WithinRange).
ValueRange in this form is not suitable to add new constraints on
arguments like "not-null".

This refactor introduces a new base class ValueConstraint with an
abstract apply function. Descendants must override this. There are 2
descendants: RangeConstraint and ComparisonConstraint. In the following
patches I am planning to add the NotNullConstraint, and additional
virtual functions like `negate()` and `warning()`.

Reviewers: NoQ, Szelethus, balazske, gamesh411, baloghadamsoftware, steakhal

Subscribers: whisperity, xazax.hun, szepet, rnkovacs, a.sidorin, 
mikhail.ramalho, donat.nagy, dkrupp, Charusso, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 6af63fc28e23..210a4ff199c6 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -71,14 +71,6 @@ class StdLibraryFunctionsChecker : public 
Checker {
   /// to us. If he doesn't, he performs additional invalidations.
   enum InvalidationKind { NoEvalCall, EvalCallAsPure };
 
-  /// A pair of ValueRangeKind and IntRangeVector would describe a range
-  /// imposed on a particular argument or return value symbol.
-  ///
-  /// Given a range, should the argument stay inside or outside this range?
-  /// The special `ComparesToArgument' value indicates that we should
-  /// impose a constraint that involves other argument or return value symbols.
-  enum ValueRangeKind { OutOfRange, WithinRange, ComparesToArgument };
-
   // The universal integral type to use in value range descriptions.
   // Unsigned to make sure overflows are well-defined.
   typedef uint64_t RangeInt;
@@ -93,44 +85,42 @@ class StdLibraryFunctionsChecker : public 
Checker {
   /// ArgNo in CallExpr and CallEvent is defined as Unsigned, but
   /// obviously uint32_t should be enough for all practical purposes.
   typedef uint32_t ArgNo;
-  static const ArgNo Ret = std::numeric_limits::max();
-
-  /// Incapsulates a single range on a single symbol within a branch.
-  class ValueRange {
-ArgNo ArgN;  // Argument to which we apply the range.
-ValueRangeKind Kind; // Kind of range definition.
-IntRangeVector Args; // Polymorphic arguments.
+  static const ArgNo Ret;
 
+  /// Polymorphic base class that represents a constraint on a given argument
+  /// (or return value) of a function. Derived classes implement 
diff erent kind
+  /// of constraints, e.g range constraints or correlation between two
+  /// arguments.
+  class ValueConstraint {
   public:
-ValueRange(ArgNo ArgN, ValueRangeKind Kind, const IntRangeVector &Args)
-: ArgN(ArgN), Kind(Kind), Args(Args) {}
-
+ValueConstraint(ArgNo ArgN) : ArgN(ArgN) {}
+virtual ~ValueConstraint() {}
+/// Apply the effects of the constraint on the given program state. If null
+/// is returned then the constraint is not feasible.
+virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary) const = 0;
 ArgNo getArgNo() const { return ArgN; }
-ValueRangeKind getKind() const { return Kind; }
-
-BinaryOperator::Opcode getOpcode() const {
-  assert(Kind == ComparesToArgument);
-  assert(Args.size() == 1);
-  BinaryOperator::Opcode Op =
-  static_cast(Args[0].first);
-  assert(BinaryOperator::isComparisonOp(Op) &&
- "Only comparison ops are supported for ComparesToArgument");
-  return Op;
-}
 
-ArgNo getOtherArgNo() const {
-  assert(Kind == ComparesToArgument);
-  assert(Args.size() == 1);
-  return static_cast(Args[0].second);
-}
+  protected:
+ArgNo ArgN; // Argument to which we apply the constraint.
+  };
+
+  /// Given a range, should the argument stay inside or outside this range?
+  enum RangeKind { OutOfRange, WithinRange };
+
+  /// Encapsulates a single range on a single symbol within a branch.
+  class RangeConstraint : public ValueConstraint {
+RangeKind Kind; 

[PATCH] D74973: [analyzer] StdLibraryFunctionsChecker refactor w/ inheritance

2020-03-17 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 250732.
martong marked 3 inline comments as done.
martong added a comment.

- Rebase to master
- Add comments to ValueConstraint
- Add virtual dtor
- Add comments to ValueConstraintPtr


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74973

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -71,14 +71,6 @@
   /// to us. If he doesn't, he performs additional invalidations.
   enum InvalidationKind { NoEvalCall, EvalCallAsPure };
 
-  /// A pair of ValueRangeKind and IntRangeVector would describe a range
-  /// imposed on a particular argument or return value symbol.
-  ///
-  /// Given a range, should the argument stay inside or outside this range?
-  /// The special `ComparesToArgument' value indicates that we should
-  /// impose a constraint that involves other argument or return value symbols.
-  enum ValueRangeKind { OutOfRange, WithinRange, ComparesToArgument };
-
   // The universal integral type to use in value range descriptions.
   // Unsigned to make sure overflows are well-defined.
   typedef uint64_t RangeInt;
@@ -93,44 +85,42 @@
   /// ArgNo in CallExpr and CallEvent is defined as Unsigned, but
   /// obviously uint32_t should be enough for all practical purposes.
   typedef uint32_t ArgNo;
-  static const ArgNo Ret = std::numeric_limits::max();
-
-  /// Incapsulates a single range on a single symbol within a branch.
-  class ValueRange {
-ArgNo ArgN;  // Argument to which we apply the range.
-ValueRangeKind Kind; // Kind of range definition.
-IntRangeVector Args; // Polymorphic arguments.
+  static const ArgNo Ret;
 
+  /// Polymorphic base class that represents a constraint on a given argument
+  /// (or return value) of a function. Derived classes implement different kind
+  /// of constraints, e.g range constraints or correlation between two
+  /// arguments.
+  class ValueConstraint {
   public:
-ValueRange(ArgNo ArgN, ValueRangeKind Kind, const IntRangeVector &Args)
-: ArgN(ArgN), Kind(Kind), Args(Args) {}
-
+ValueConstraint(ArgNo ArgN) : ArgN(ArgN) {}
+virtual ~ValueConstraint() {}
+/// Apply the effects of the constraint on the given program state. If null
+/// is returned then the constraint is not feasible.
+virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary) const = 0;
 ArgNo getArgNo() const { return ArgN; }
-ValueRangeKind getKind() const { return Kind; }
-
-BinaryOperator::Opcode getOpcode() const {
-  assert(Kind == ComparesToArgument);
-  assert(Args.size() == 1);
-  BinaryOperator::Opcode Op =
-  static_cast(Args[0].first);
-  assert(BinaryOperator::isComparisonOp(Op) &&
- "Only comparison ops are supported for ComparesToArgument");
-  return Op;
-}
 
-ArgNo getOtherArgNo() const {
-  assert(Kind == ComparesToArgument);
-  assert(Args.size() == 1);
-  return static_cast(Args[0].second);
-}
+  protected:
+ArgNo ArgN; // Argument to which we apply the constraint.
+  };
+
+  /// Given a range, should the argument stay inside or outside this range?
+  enum RangeKind { OutOfRange, WithinRange };
+
+  /// Encapsulates a single range on a single symbol within a branch.
+  class RangeConstraint : public ValueConstraint {
+RangeKind Kind;  // Kind of range definition.
+IntRangeVector Args; // Polymorphic arguments.
+
+  public:
+RangeConstraint(ArgNo ArgN, RangeKind Kind, const IntRangeVector &Args)
+: ValueConstraint(ArgN), Kind(Kind), Args(Args) {}
 
 const IntRangeVector &getRanges() const {
-  assert(Kind != ComparesToArgument);
   return Args;
 }
 
-// We avoid creating a virtual apply() method because
-// it makes initializer lists harder to write.
   private:
 ProgramStateRef applyAsOutOfRange(ProgramStateRef State,
   const CallEvent &Call,
@@ -138,30 +128,44 @@
 ProgramStateRef applyAsWithinRange(ProgramStateRef State,
const CallEvent &Call,
const Summary &Summary) const;
-ProgramStateRef applyAsComparesToArgument(ProgramStateRef State,
-  const CallEvent &Call,
-  const Summary &Summary) const;
-
   public:
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
-  const Summary &Summary) const {
+  const Summary &Summary) 

[PATCH] D75687: [clangd] Only minimally escape text when rendering to markdown.

2020-03-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added a comment.

Filed https://github.com/google/llvm-premerge-checks/issues/147 for the 
spurious unit test failure.




Comment at: clang-tools-extra/clangd/FormattedString.cpp:150
+// Not a delimiter if surrounded by space.
+return !SpaceSurrounds();
+  case '-': // Setex heading, horizontal ruler, or bullet.

kadircet wrote:
> kadircet wrote:
> > `_` seems to behave different than `*` :(
> > 
> > it seems to rather depend on the spaces around the text being emphasized, 
> > i.e
> > 
> > ```
> > foo _ bar _ foo -> no emphasis
> > foo _ bar_ foo -> no emphasis
> > foo _bar_ foo -> emphasis on bar
> > foo_bar_ foo -> no emphasis
> > ```
> > 
> > so this should rather be `Before.endswith(" ") && isAlpha(After)` for the 
> > beginning of emphasis and the opposite for the ending.
> > Not sure if there's an easy way to decide on it in isolation.
> regarding this one, i suppose we'll just be escaping in some unnecessary 
> cases(like the 2nd and the 4th), but still better than the current state so 
> nvm.
Oops, I forgot to reply to this one. Good catch that `*` and `_` are different.
The rules are indeed really complicated (particularly for _ next to 
punctuation) and we don't know whether we are at the start or end.

However my reading of the spec says alnum_alnum never needs to be escaped, and 
that's incredibly common, so I've added that special case. (Same is true for 
alnum___alnum, but I don't think that's common enough to bother with).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75687



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


[PATCH] D75687: [clangd] Only minimally escape text when rendering to markdown.

2020-03-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 250730.
sammccall added a comment.

Fix '_' rules.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75687

Files:
  clang-tools-extra/clangd/FormattedString.cpp
  clang-tools-extra/clangd/FormattedString.h
  clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1905,7 +1905,7 @@
   llvm::StringRef ExpectedMarkdown = R"md(### variable `foo`  
 
 ---
-Value \= `val`  
+Value = `val`  
 
 ---
 ```cpp
Index: clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
===
--- clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
+++ clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
@@ -17,25 +17,96 @@
 namespace markup {
 namespace {
 
-TEST(Render, Escaping) {
-  // Check some ASCII punctuation
-  Paragraph P;
-  P.appendText("*!`");
-  EXPECT_EQ(P.asMarkdown(), "\\*\\!\\`");
+std::string escape(llvm::StringRef Text) {
+  return Paragraph().appendText(Text.str()).asMarkdown();
+}
+
+MATCHER_P(escaped, C, "") {
+  return testing::ExplainMatchResult(::testing::HasSubstr(std::string{'\\', C}),
+ arg, result_listener);
+}
 
+MATCHER(escapedNone, "") {
+  return testing::ExplainMatchResult(::testing::Not(::testing::HasSubstr("\\")),
+ arg, result_listener);
+}
+
+TEST(Render, Escaping) {
   // Check all ASCII punctuation.
-  P = Paragraph();
   std::string Punctuation = R"txt(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)txt";
-  // Same text, with each character escaped.
-  std::string EscapedPunctuation;
-  EscapedPunctuation.reserve(2 * Punctuation.size());
-  for (char C : Punctuation)
-EscapedPunctuation += std::string("\\") + C;
-  P.appendText(Punctuation);
-  EXPECT_EQ(P.asMarkdown(), EscapedPunctuation);
+  std::string EscapedPunc = R"txt(!"#$%&'()\*+,-./:;<=>?@[\\]^\_\`{|}~)txt";
+  EXPECT_EQ(escape(Punctuation), EscapedPunc);
+
+  // Inline code
+  EXPECT_EQ(escape("`foo`"), R"(\`foo\`)");
+  EXPECT_EQ(escape("`foo"), R"(\`foo)");
+  EXPECT_EQ(escape("foo`"), R"(foo\`)");
+  EXPECT_EQ(escape("``foo``"), R"(\`\`foo\`\`)");
+  // Code blocks
+  EXPECT_EQ(escape("```"), R"(\`\`\`)"); // This could also be inline code!
+  EXPECT_EQ(escape("~~~"), R"(\~~~)");
+
+  // Rulers and headings
+  EXPECT_THAT(escape("## Heading"), escaped('#'));
+  EXPECT_THAT(escape("Foo # bar"), escapedNone());
+  EXPECT_EQ(escape("---"), R"(\---)");
+  EXPECT_EQ(escape("-"), R"(\-)");
+  EXPECT_EQ(escape("==="), R"(\===)");
+  EXPECT_EQ(escape("="), R"(\=)");
+  EXPECT_EQ(escape("***"), R"(\*\*\*)"); // \** could start emphasis!
+
+  // HTML tags.
+  EXPECT_THAT(escape(""), escaped('<'));
+  EXPECT_THAT(escape("std::vector"), escaped('<'));
+  EXPECT_THAT(escape("std::map"), escapedNone());
+  // Autolinks
+  EXPECT_THAT(escape("Email "), escapedNone());
+  EXPECT_THAT(escape("Website "), escapedNone());
+
+  // Bullet lists.
+  EXPECT_THAT(escape("- foo"), escaped('-'));
+  EXPECT_THAT(escape("* foo"), escaped('*'));
+  EXPECT_THAT(escape("+ foo"), escaped('+'));
+  EXPECT_THAT(escape("+"), escaped('+'));
+  EXPECT_THAT(escape("a + foo"), escapedNone());
+  EXPECT_THAT(escape("a+ foo"), escapedNone());
+  EXPECT_THAT(escape("1. foo"), escaped('.'));
+  EXPECT_THAT(escape("a. foo"), escapedNone());
+
+  // Emphasis.
+  EXPECT_EQ(escape("*foo*"), R"(\*foo\*)");
+  EXPECT_EQ(escape("**foo**"), R"(\*\*foo\*\*)");
+  EXPECT_THAT(escape("*foo"), escaped('*'));
+  EXPECT_THAT(escape("foo *"), escapedNone());
+  EXPECT_THAT(escape("foo * bar"), escapedNone());
+  EXPECT_THAT(escape("foo_bar"), escapedNone());
+  EXPECT_THAT(escape("foo _bar"), escaped('_'));
+  EXPECT_THAT(escape("foo_ bar"), escaped('_'));
+  EXPECT_THAT(escape("foo _ bar"), escapedNone());
+
+  // HTML entities.
+  EXPECT_THAT(escape("fish &chips;"), escaped('&'));
+  EXPECT_THAT(escape("fish & chips;"), escapedNone());
+  EXPECT_THAT(escape("fish &chips"), escapedNone());
+  EXPECT_THAT(escape("foo * bar"), escaped('&'));
+  EXPECT_THAT(escape("foo ¯ bar"), escaped('&'));
+  EXPECT_THAT(escape("foo &?; bar"), escapedNone());
+
+  // Links.
+  EXPECT_THAT(escape("[foo](bar)"), escaped(']'));
+  EXPECT_THAT(escape("[foo]: bar"), escaped(']'));
+  // No need to escape these, as the target never exists.
+  EXPECT_THAT(escape("[foo][]"), escapedNone());
+  EXPECT_THAT(escape("[foo][bar]"), escapedNone());
+  EXPECT_THAT(escape("[foo]"), escapedNone());
 
   // In code blocks we don't need to escape ASCII punctuation.
-  P = Paragraph();
+  Paragraph P = Paragraph();
   P.appendCode("* foo !+ bar * baz");

[PATCH] D76181: [AVR] Add support for the -mdouble=x flag

2020-03-17 Thread Ayke via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4add24920550: [AVR] Add support for the -mdouble=x flag 
(authored by aykevl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76181

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/mdouble.c
  clang/test/Driver/mdouble.c

Index: clang/test/Driver/mdouble.c
===
--- /dev/null
+++ clang/test/Driver/mdouble.c
@@ -0,0 +1,7 @@
+// RUN: %clang -target avr -c -### %s -mdouble=64 2>&1 | FileCheck %s
+
+// CHECK: "-mdouble=64"
+
+// RUN: %clang -target aarch64 -c -### %s -mdouble=64 2>&1 | FileCheck --check-prefix=ERR %s
+
+// ERR: error: unsupported option '-mdouble=64' for target 'aarch64'
Index: clang/test/CodeGen/mdouble.c
===
--- /dev/null
+++ clang/test/CodeGen/mdouble.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=avr-unknown-unknown -mdouble=64 | \
+// RUN:   FileCheck --check-prefix=AVR-FP64 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=avr-unknown-unknown -mdouble=32 | \
+// RUN:   FileCheck --check-prefix=AVR-FP32 %s
+
+double x = 0;
+int size = sizeof(x);
+
+// FIXME: the double should have an alignment of 1 on AVR, not 4 or 8.
+// AVR-FP64: @x = global double {{.*}}, align 8
+// AVR-FP64: @size = global i16 8
+// AVR-FP32: @x = global float {{.*}}, align 4
+// AVR-FP32: @size = global i16 4
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2937,6 +2937,7 @@
   Opts.PackStruct = getLastArgIntValue(Args, OPT_fpack_struct_EQ, 0, Diags);
   Opts.MaxTypeAlign = getLastArgIntValue(Args, OPT_fmax_type_align_EQ, 0, Diags);
   Opts.AlignDouble = Args.hasArg(OPT_malign_double);
+  Opts.DoubleSize = getLastArgIntValue(Args, OPT_mdouble_EQ, 0, Diags);
   Opts.LongDoubleSize = Args.hasArg(OPT_mlong_double_128)
 ? 128
 : Args.hasArg(OPT_mlong_double_64) ? 64 : 0;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4580,6 +4580,14 @@
   RenderFloatingPointOptions(TC, D, OFastEnabled, Args, CmdArgs,
  JA.getOffloadingDeviceKind());
 
+  if (Arg *A = Args.getLastArg(options::OPT_mdouble_EQ)) {
+if (TC.getArch() == llvm::Triple::avr)
+  A->render(Args, CmdArgs);
+else
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getAsString(Args) << TripleStr;
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
 if (TC.getTriple().isX86())
   A->render(Args, CmdArgs);
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -380,6 +380,20 @@
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
   }
 
+  if (Opts.DoubleSize) {
+if (Opts.DoubleSize == 32) {
+  DoubleWidth = 32;
+  LongDoubleWidth = 32;
+  DoubleFormat = &llvm::APFloat::IEEEsingle();
+  LongDoubleFormat = &llvm::APFloat::IEEEsingle();
+} else if (Opts.DoubleSize == 64) {
+  DoubleWidth = 64;
+  LongDoubleWidth = 64;
+  DoubleFormat = &llvm::APFloat::IEEEdouble();
+  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
+}
+  }
+
   if (Opts.LongDoubleSize) {
 if (Opts.LongDoubleSize == DoubleWidth) {
   LongDoubleWidth = DoubleWidth;
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2179,6 +2179,8 @@
 def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, Group;
 def mlong_calls : Flag<["-"], "mlong-calls">, Group,
   HelpText<"Generate branches with extended addressability, usually via indirect jumps.">;
+def mdouble_EQ : Joined<["-"], "mdouble=">, Group, Values<"32,64">, Flags<[CC1Option]>,
+  HelpText<"Force double to be 32 bits or 64 bits">;
 def LongDouble_Group : OptionGroup<"">, Group,
   DocName<"Long double flags">,
   DocBrief<[{Selects the long double implementation}]>;
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -176,6 +176,7 @@
 VALUE_LANGOPT(MaxTypeAlign  , 32, 0,
   "default maximum alignment for types")
 VALUE_LAN

[PATCH] D74973: [analyzer] StdLibraryFunctionsChecker refactor w/ inheritance

2020-03-17 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 12 inline comments as done.
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:88
   typedef uint32_t ArgNo;
-  static const ArgNo Ret = std::numeric_limits::max();
+  static const ArgNo Ret;
+

Szelethus wrote:
> Why did we remove the initialization here? Can we make this `constexpr`?
I am receiving an undefined reference linker error (I use `gold`) if the 
initialization is happening in-class.  
Even if `constexpr` is used.

```
/usr/bin/ld.gold: error: 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StdLibraryFunctionsChecker.cpp.o:
 requires dynamic R_X86_64_PC32 reloc against 
'_ZN12_GLOBAL__N_126StdLibraryFunctionsChecker3RetE' which may overflow at 
runtime; recompile with -fPIC
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StdLibraryFunctionsChecker.cpp.o:StdLibraryFunctionsChecker.cpp:function
 (anonymous 
namespace)::StdLibraryFunctionsChecker::initFunctionSummaries(clang::ento::CheckerContext&)
 const: error: undefined reference to '(anonymous 
namespace)::StdLibraryFunctionsChecker::Ret'
```



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:90
+
+  class ValueConstraint {
+  public:

Szelethus wrote:
> We should totally have a good bit of documentation here.
Ok, I added some comments to the class and to `apply` as well.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:151
+
+  using ValueConstraintPtr = std::shared_ptr;
+  /// The complete list of constraints that defines a single branch.

baloghadamsoftware wrote:
> baloghadamsoftware wrote:
> > Szelethus wrote:
> > > martong wrote:
> > > > Szelethus wrote:
> > > > > martong wrote:
> > > > > > martong wrote:
> > > > > > > Szelethus wrote:
> > > > > > > > gamesh411 wrote:
> > > > > > > > > martong wrote:
> > > > > > > > > > Note here, we need a copyable, polymorphic and default 
> > > > > > > > > > initializable type (vector needs that). A raw pointer were 
> > > > > > > > > > good, however, we cannot default initialize that. 
> > > > > > > > > > unique_ptr makes the Summary class non-copyable, therefore 
> > > > > > > > > > not an option.
> > > > > > > > > > Releasing the copyablitly requirement would render the 
> > > > > > > > > > initialization of the Summary map infeasible.
> > > > > > > > > > Perhaps we could come up with a [[ 
> > > > > > > > > > https://www.youtube.com/watch?v=bIhUE5uUFOA | type erasure 
> > > > > > > > > > technique without inheritance ]] once we consider the 
> > > > > > > > > > shared_ptr as restriction, but for now that seems to be 
> > > > > > > > > > overkill.
> > > > > > > > > std::variant (with std::monostate for the default 
> > > > > > > > > constructibility) would also be an option  (if c++17 were 
> > > > > > > > > supported). But this is not really an issue, i agree with 
> > > > > > > > > that.
> > > > > > > > Ugh, we've historically been very hostile towards virtual 
> > > > > > > > functions. We don't mind them that much when they don't have to 
> > > > > > > > run a lot, like during bug report construction, but as a core 
> > > > > > > > part of the analysis, I'm not sure what the current stance is 
> > > > > > > > on it.
> > > > > > > > 
> > > > > > > > I'm not inherently (haha) against it, and I'm fine with leaving 
> > > > > > > > this as-is for the time being, though I'd prefer if you placed 
> > > > > > > > a `TODO` to revisit this issue.
> > > > > > > > std::variant (with std::monostate for the default 
> > > > > > > > constructibility) would also be an option (if c++17 were 
> > > > > > > > supported). But this is not really an issue, i agree with that.
> > > > > > > 
> > > > > > > Variant would be useful if we knew the set of classes prior and 
> > > > > > > we wanted to add operations gradually. Class hierarchies (or 
> > > > > > > run-time concepts [Sean Parent]) are very useful if we know the 
> > > > > > > set of operations prior and we want to add classes gradually, and 
> > > > > > > we have this case here.
> > > > > > > Ugh, we've historically been very hostile towards virtual 
> > > > > > > functions. We don't mind them that much when they don't have to 
> > > > > > > run a lot, like during bug report construction, but as a core 
> > > > > > > part of the analysis, I'm not sure what the current stance is on 
> > > > > > > it.
> > > > > > 
> > > > > > I did not find any evidence for this statement. Consider as a 
> > > > > > counter example the ExternalASTSource interface in Clang, which is 
> > > > > > filled with virtual functions and is part of the C/C++ lookup 
> > > > > > mechanism, which is quite on the hot path of C/C++ parsing I think. 
> > > > > > Did not find any prohibition in LLVM coding guidelines neither. I 
> > > > > > do believe virtual functions have their use case

[PATCH] D76218: [Sema][SVE] Reject "new" with sizeless types

2020-03-17 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG506406c4d592: [Sema][SVE] Reject "new" with 
sizeless types (authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76218

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -411,6 +411,15 @@
   } catch (svint8_t &) { // expected-error {{cannot catch reference to 
sizeless type 'svint8_t'}}
   }
 
+  new svint8_t; // expected-error {{allocation of sizeless type 
'svint8_t'}}
+  new svint8_t();   // expected-error {{allocation of sizeless type 
'svint8_t'}}
+  new svint8_t[10]; // expected-error {{allocation of sizeless type 
'svint8_t'}}
+  new svint8_t *;
+
+  new (global_int8_ptr) svint8_t; // expected-error {{allocation of 
sizeless type 'svint8_t'}}
+  new (global_int8_ptr) svint8_t();   // expected-error {{allocation of 
sizeless type 'svint8_t'}}
+  new (global_int8_ptr) svint8_t[10]; // expected-error {{allocation of 
sizeless type 'svint8_t'}}
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of 
non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a 
pseudo-destructor expression}}
 
   (void)svint8_t();
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -2340,7 +2340,8 @@
 return Diag(Loc, diag::err_bad_new_type)
   << AllocType << 1 << R;
   else if (!AllocType->isDependentType() &&
-   RequireCompleteType(Loc, AllocType, 
diag::err_new_incomplete_type,R))
+   RequireCompleteSizedType(
+   Loc, AllocType, diag::err_new_incomplete_or_sizeless_type, R))
 return true;
   else if (RequireNonAbstractType(Loc, AllocType,
   diag::err_allocation_of_abstract_type))
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6897,8 +6897,8 @@
   "array size must be specified in new expression with no initializer">;
 def err_bad_new_type : Error<
   "cannot allocate %select{function|reference}1 type %0 with new">;
-def err_new_incomplete_type : Error<
-  "allocation of incomplete type %0">;
+def err_new_incomplete_or_sizeless_type : Error<
+  "allocation of %select{incomplete|sizeless}0 type %1">;
 def err_new_array_nonconst : Error<
   "only the first dimension of an allocated array may have dynamic size">;
 def err_new_array_size_unknown_from_init : Error<


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -411,6 +411,15 @@
   } catch (svint8_t &) { // expected-error {{cannot catch reference to sizeless type 'svint8_t'}}
   }
 
+  new svint8_t; // expected-error {{allocation of sizeless type 'svint8_t'}}
+  new svint8_t();   // expected-error {{allocation of sizeless type 'svint8_t'}}
+  new svint8_t[10]; // expected-error {{allocation of sizeless type 'svint8_t'}}
+  new svint8_t *;
+
+  new (global_int8_ptr) svint8_t; // expected-error {{allocation of sizeless type 'svint8_t'}}
+  new (global_int8_ptr) svint8_t();   // expected-error {{allocation of sizeless type 'svint8_t'}}
+  new (global_int8_ptr) svint8_t[10]; // expected-error {{allocation of sizeless type 'svint8_t'}}
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a pseudo-destructor expression}}
 
   (void)svint8_t();
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -2340,7 +2340,8 @@
 return Diag(Loc, diag::err_bad_new_type)
   << AllocType << 1 << R;
   else if (!AllocType->isDependentType() &&
-   RequireCompleteType(Loc, AllocType, diag::err_new_incomplete_type,R))
+   RequireCompleteSizedType(
+   Loc, AllocType, diag::err_new_incomplete_or_sizeless_type, R))
 return true;
   else if (RequireNonAbstractType(Loc, AllocType,
   diag::err_allocation_of_abstract_type))
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6897,8 +6897,8 @@
   "array size must be specified in new e

[PATCH] D74973: [analyzer] StdLibraryFunctionsChecker refactor w/ inheritance

2020-03-17 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc6b8484e855b: [analyzer] StdLibraryFunctionsChecker refactor 
w/ inheritance (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74973

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -71,14 +71,6 @@
   /// to us. If he doesn't, he performs additional invalidations.
   enum InvalidationKind { NoEvalCall, EvalCallAsPure };
 
-  /// A pair of ValueRangeKind and IntRangeVector would describe a range
-  /// imposed on a particular argument or return value symbol.
-  ///
-  /// Given a range, should the argument stay inside or outside this range?
-  /// The special `ComparesToArgument' value indicates that we should
-  /// impose a constraint that involves other argument or return value symbols.
-  enum ValueRangeKind { OutOfRange, WithinRange, ComparesToArgument };
-
   // The universal integral type to use in value range descriptions.
   // Unsigned to make sure overflows are well-defined.
   typedef uint64_t RangeInt;
@@ -93,44 +85,42 @@
   /// ArgNo in CallExpr and CallEvent is defined as Unsigned, but
   /// obviously uint32_t should be enough for all practical purposes.
   typedef uint32_t ArgNo;
-  static const ArgNo Ret = std::numeric_limits::max();
-
-  /// Incapsulates a single range on a single symbol within a branch.
-  class ValueRange {
-ArgNo ArgN;  // Argument to which we apply the range.
-ValueRangeKind Kind; // Kind of range definition.
-IntRangeVector Args; // Polymorphic arguments.
+  static const ArgNo Ret;
 
+  /// Polymorphic base class that represents a constraint on a given argument
+  /// (or return value) of a function. Derived classes implement different kind
+  /// of constraints, e.g range constraints or correlation between two
+  /// arguments.
+  class ValueConstraint {
   public:
-ValueRange(ArgNo ArgN, ValueRangeKind Kind, const IntRangeVector &Args)
-: ArgN(ArgN), Kind(Kind), Args(Args) {}
-
+ValueConstraint(ArgNo ArgN) : ArgN(ArgN) {}
+virtual ~ValueConstraint() {}
+/// Apply the effects of the constraint on the given program state. If null
+/// is returned then the constraint is not feasible.
+virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
+  const Summary &Summary) const = 0;
 ArgNo getArgNo() const { return ArgN; }
-ValueRangeKind getKind() const { return Kind; }
-
-BinaryOperator::Opcode getOpcode() const {
-  assert(Kind == ComparesToArgument);
-  assert(Args.size() == 1);
-  BinaryOperator::Opcode Op =
-  static_cast(Args[0].first);
-  assert(BinaryOperator::isComparisonOp(Op) &&
- "Only comparison ops are supported for ComparesToArgument");
-  return Op;
-}
 
-ArgNo getOtherArgNo() const {
-  assert(Kind == ComparesToArgument);
-  assert(Args.size() == 1);
-  return static_cast(Args[0].second);
-}
+  protected:
+ArgNo ArgN; // Argument to which we apply the constraint.
+  };
+
+  /// Given a range, should the argument stay inside or outside this range?
+  enum RangeKind { OutOfRange, WithinRange };
+
+  /// Encapsulates a single range on a single symbol within a branch.
+  class RangeConstraint : public ValueConstraint {
+RangeKind Kind;  // Kind of range definition.
+IntRangeVector Args; // Polymorphic arguments.
+
+  public:
+RangeConstraint(ArgNo ArgN, RangeKind Kind, const IntRangeVector &Args)
+: ValueConstraint(ArgN), Kind(Kind), Args(Args) {}
 
 const IntRangeVector &getRanges() const {
-  assert(Kind != ComparesToArgument);
   return Args;
 }
 
-// We avoid creating a virtual apply() method because
-// it makes initializer lists harder to write.
   private:
 ProgramStateRef applyAsOutOfRange(ProgramStateRef State,
   const CallEvent &Call,
@@ -138,30 +128,44 @@
 ProgramStateRef applyAsWithinRange(ProgramStateRef State,
const CallEvent &Call,
const Summary &Summary) const;
-ProgramStateRef applyAsComparesToArgument(ProgramStateRef State,
-  const CallEvent &Call,
-  const Summary &Summary) const;
-
   public:
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
-  const Summary &Summary) const {
+  const Summary &Summary) const override {
   switch 

[clang] 4ece6f0 - [Sema][SVE] Reject "delete" with sizeless types

2020-03-17 Thread Richard Sandiford via cfe-commits

Author: Richard Sandiford
Date: 2020-03-17T12:45:00Z
New Revision: 4ece6f051bd088fb8d4862bedf590f4f9d86cd17

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

LOG: [Sema][SVE] Reject "delete" with sizeless types

Sizeless types can't be used with "new", so it doesn't make sense
to use them with "delete" either.  The SVE ACLE therefore doesn't
allow that.

This is slightly stronger than for normal incomplete types, since:

  struct S;
  void f(S *s) { delete s; }

is (by necessity) just a default-on warning rather than an error.

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

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f50e5ea02c86..24e312ef6d01 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3467,7 +3467,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   // this, so we treat it as a warning unless we're in a SFINAE context.
   Diag(StartLoc, diag::ext_delete_void_ptr_operand)
 << Type << Ex.get()->getSourceRange();
-} else if (Pointee->isFunctionType() || Pointee->isVoidType()) {
+} else if (Pointee->isFunctionType() || Pointee->isVoidType() ||
+   Pointee->isSizelessType()) {
   return ExprError(Diag(StartLoc, diag::err_delete_operand)
 << Type << Ex.get()->getSourceRange());
 } else if (!Pointee->isDependentType()) {

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp 
b/clang/test/SemaCXX/sizeless-1.cpp
index 40fa436dd1de..5cbf1923d705 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -420,6 +420,9 @@ void cxx_only(int sel) {
   new (global_int8_ptr) svint8_t();   // expected-error {{allocation of 
sizeless type 'svint8_t'}}
   new (global_int8_ptr) svint8_t[10]; // expected-error {{allocation of 
sizeless type 'svint8_t'}}
 
+  delete global_int8_ptr;   // expected-error {{cannot delete expression of 
type 'svint8_t *'}}
+  delete[] global_int8_ptr; // expected-error {{cannot delete expression of 
type 'svint8_t *'}}
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of 
non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a 
pseudo-destructor expression}}
 
   (void)svint8_t();



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


[clang] 211ba00 - [OpenCL] Add pipe and kernel enqueuing builtins

2020-03-17 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2020-03-17T13:15:32Z
New Revision: 211ba00ce00ff3feb9b1f52ece712e370c184015

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

LOG: [OpenCL] Add pipe and kernel enqueuing builtins

This excludes some builtins that take argument types not yet handled
by the `-fdeclare-opencl-builtins` machinery, and also excludes
builtins that are already defined in `Builtins.def`.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 0d8764a567a4..40798b744ced 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -288,7 +288,10 @@ def Image2dMsaaDepth  : Type<"image2d_msaa_depth_t", 
QualType<"OCLImage2dMSA
 def Image2dArrayMsaaDepth : Type<"image2d_array_msaa_depth_t", 
QualType<"OCLImage2dArrayMSAADepth", 1>>;
 
 def Sampler   : Type<"sampler_t", QualType<"OCLSamplerTy">>;
+def ClkEvent  : Type<"clk_event_t", QualType<"OCLClkEventTy">>;
 def Event : Type<"event_t", QualType<"OCLEventTy">>;
+def Queue : Type<"queue_t", QualType<"OCLQueueTy">>;
+def ReserveId : Type<"reserve_id_t", QualType<"OCLReserveIDTy">>;
 
 // OpenCL v2.0 s6.13.11: Atomic integer and floating-point types.
 def AtomicInt : Type<"atomic_int", 
QualType<"getAtomicType(Context.IntTy)">>;
@@ -1232,6 +1235,44 @@ let MinVersion = CL20 in {
 }
 
 
+//
+// OpenCL2.0 : 6.13.16 : Pipe Functions
+// --- Table 27 ---
+// Defined in Builtins.def
+
+// --- Table 28 ---
+// Builtins taking pipe arguments are defined in Builtins.def
+def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>;
+
+// --- Table 29 ---
+// Defined in Builtins.def
+
+
+//
+// OpenCL2.0 : 6.13.17 : Enqueuing Kernels
+// --- Table 30 ---
+// Defined in Builtins.def
+
+// --- Table 32 ---
+// Defined in Builtins.def
+
+// --- Table 33 ---
+def : Builtin<"enqueue_marker",
+[Int, Queue, UInt, PointerType, GenericAS>, 
PointerType]>;
+
+// --- Table 34 ---
+def : Builtin<"retain_event", [Void, ClkEvent]>;
+def : Builtin<"release_event", [Void, ClkEvent]>;
+def : Builtin<"create_user_event", [ClkEvent]>;
+def : Builtin<"is_valid_event", [Bool, ClkEvent]>;
+def : Builtin<"set_user_event_status", [Void, ClkEvent, Int]>;
+// TODO: capture_event_profiling_info
+
+// --- Table 35 ---
+def : Builtin<"get_default_queue", [Queue]>;
+// TODO: ndrange functions
+
+
 // OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
 let MinVersion = CL20 in {
   let Extension = FuncExtKhrSubgroups in {



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


[PATCH] D76219: [Sema][SVE] Reject "delete" with sizeless types

2020-03-17 Thread Richard Sandiford via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ece6f051bd0: [Sema][SVE] Reject "delete" with 
sizeless types (authored by rsandifo-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76219

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -420,6 +420,9 @@
   new (global_int8_ptr) svint8_t();   // expected-error {{allocation of 
sizeless type 'svint8_t'}}
   new (global_int8_ptr) svint8_t[10]; // expected-error {{allocation of 
sizeless type 'svint8_t'}}
 
+  delete global_int8_ptr;   // expected-error {{cannot delete expression of 
type 'svint8_t *'}}
+  delete[] global_int8_ptr; // expected-error {{cannot delete expression of 
type 'svint8_t *'}}
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of 
non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a 
pseudo-destructor expression}}
 
   (void)svint8_t();
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -3467,7 +3467,8 @@
   // this, so we treat it as a warning unless we're in a SFINAE context.
   Diag(StartLoc, diag::ext_delete_void_ptr_operand)
 << Type << Ex.get()->getSourceRange();
-} else if (Pointee->isFunctionType() || Pointee->isVoidType()) {
+} else if (Pointee->isFunctionType() || Pointee->isVoidType() ||
+   Pointee->isSizelessType()) {
   return ExprError(Diag(StartLoc, diag::err_delete_operand)
 << Type << Ex.get()->getSourceRange());
 } else if (!Pointee->isDependentType()) {


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -420,6 +420,9 @@
   new (global_int8_ptr) svint8_t();   // expected-error {{allocation of sizeless type 'svint8_t'}}
   new (global_int8_ptr) svint8_t[10]; // expected-error {{allocation of sizeless type 'svint8_t'}}
 
+  delete global_int8_ptr;   // expected-error {{cannot delete expression of type 'svint8_t *'}}
+  delete[] global_int8_ptr; // expected-error {{cannot delete expression of type 'svint8_t *'}}
+
   local_int8.~__SVInt8_t(); // expected-error {{object expression of non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a pseudo-destructor expression}}
 
   (void)svint8_t();
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -3467,7 +3467,8 @@
   // this, so we treat it as a warning unless we're in a SFINAE context.
   Diag(StartLoc, diag::ext_delete_void_ptr_operand)
 << Type << Ex.get()->getSourceRange();
-} else if (Pointee->isFunctionType() || Pointee->isVoidType()) {
+} else if (Pointee->isFunctionType() || Pointee->isVoidType() ||
+   Pointee->isSizelessType()) {
   return ExprError(Diag(StartLoc, diag::err_delete_operand)
 << Type << Ex.get()->getSourceRange());
 } else if (!Pointee->isDependentType()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75579: Replace MCTargetOptionsCommandFlags.inc and CommandFlags.inc by runtime-registration

2020-03-17 Thread serge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac1d23ed7de0: Replace MCTargetOptionsCommandFlags.inc and 
CommandFlags.inc by runtime… (authored by serge-sans-paille).

Changed prior to commit:
  https://reviews.llvm.org/D75579?vs=250631&id=250747#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75579

Files:
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  lld/Common/TargetOptionsCommandFlags.cpp
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/CommandFlags.inc
  llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
  llvm/include/llvm/MC/MCTargetOptionsCommandFlags.inc
  llvm/include/llvm/module.modulemap
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/MC/CMakeLists.txt
  llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
  llvm/tools/dsymutil/DwarfStreamer.cpp
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llc/CMakeLists.txt
  llvm/tools/llc/llc.cpp
  llvm/tools/lli/CMakeLists.txt
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-dwp/llvm-dwp.cpp
  llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
  llvm/tools/llvm-lto/CMakeLists.txt
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/CMakeLists.txt
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/llvm-mc-assemble-fuzzer/CMakeLists.txt
  llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp
  llvm/tools/llvm-mc/CMakeLists.txt
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-mca/llvm-mca.cpp
  llvm/tools/llvm-ml/llvm-ml.cpp
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
  llvm/tools/lto/CMakeLists.txt
  llvm/tools/lto/lto.cpp
  llvm/tools/opt/opt.cpp
  llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp

Index: llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
===
--- llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
+++ llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
@@ -25,7 +25,7 @@
 #include "llvm/MC/MCRegisterInfo.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSubtargetInfo.h"
-#include "llvm/MC/MCTargetOptionsCommandFlags.inc"
+#include "llvm/MC/MCTargetOptionsCommandFlags.h"
 #include "llvm/PassAnalysisSupport.h"
 #include "llvm/Support/LEB128.h"
 #include "llvm/Support/TargetRegistry.h"
@@ -37,6 +37,8 @@
 using namespace llvm;
 using namespace dwarf;
 
+mc::RegisterMCTargetOptionsFlags MOF;
+
 namespace {} // end anonymous namespace
 
 //===--===//
@@ -433,7 +435,7 @@
TripleName,
inconvertibleErrorCode());
 
-  MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
+  MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
   MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
   if (!MAI)
 return make_error("no asm info for target " + TripleName,
Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -22,7 +22,7 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeWriterPass.h"
-#include "llvm/CodeGen/CommandFlags.inc"
+#include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/DataLayout.h"
@@ -62,6 +62,8 @@
 using namespace llvm;
 using namespace opt_tool;
 
+static codegen::RegisterCodeGenFlags CFG;
+
 // The OptimizationList is automatically populated with registered Passes by the
 // PassNameParser.
 //
@@ -485,16 +487,17 @@
StringRef FeaturesStr,
const TargetOptions &Options) {
   std::string Error;
-  const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
- Error);
+  const Target *TheTarget =
+  TargetRegistry::lookupTarget(codegen::getMArch(), TheTriple, Error);
   // Some modules don't specify a triple, and this is okay.
   if (!TheTarget) {
 return nullptr;
   }
 
-  return TheTarget->createTargetMachine(TheTriple.getTriple(), CPUStr,
-FeaturesStr, Options, getRelocModel(),
-getCodeModel(), GetCodeGenOptLevel());
+  return TheTarget->createTargetMachine(
+  TheTriple.getTriple(), codegen::getCPUStr(), codegen::getFeaturesStr(),
+  Options, codegen::getExplicitRelocModel(),
+  codegen::getExplicitCodeModel(), GetCodeGenOptLevel());
 }
 
 #ifdef BUILD_EXAMPLES
@@ -701,11 +704,11 @@
   Triple ModuleTriple(M->getTargetTriple());
   std::string CPUStr, FeaturesStr;
   TargetMachine *Machine = nullptr;
-  const TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
+  const TargetOptions Option

[clang] 0f0564b - [OPENMP50]Initial support for detach clause in task directive.

2020-03-17 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-03-17T09:19:03-04:00
New Revision: 0f0564bb9a3ca4527eb2333eba34643e05c315ca

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

LOG: [OPENMP50]Initial support for detach clause in task directive.

Added parsing/sema/serialization support for detach clause.

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/task_ast_print.cpp
clang/test/OpenMP/task_messages.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 086c6a232de7..79f43fc8ab88 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6827,6 +6827,68 @@ class OMPDestroyClause final : public OMPClause {
   }
 };
 
+/// This represents 'detach' clause in the '#pragma omp task' directive.
+///
+/// \code
+/// #pragma omp task detach(evt)
+/// \endcode
+/// In this example directive '#pragma omp detach' has simple 'detach' clause
+/// with the variable 'evt'.
+class OMPDetachClause final : public OMPClause {
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Expression of the 'detach' clause.
+  Stmt *Evt = nullptr;
+
+  /// Set condition.
+  void setEventHandler(Expr *E) { Evt = E; }
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+public:
+  /// Build 'detach' clause with event-handler \a Evt.
+  ///
+  /// \param Evt Event handler expression.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc,
+  SourceLocation EndLoc)
+  : OMPClause(OMPC_detach, StartLoc, EndLoc), LParenLoc(LParenLoc),
+Evt(Evt) {}
+
+  /// Build an empty clause.
+  OMPDetachClause()
+  : OMPClause(OMPC_detach, SourceLocation(), SourceLocation()) {}
+
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns event-handler expression.
+  Expr *getEventHandler() const { return cast_or_null(Evt); }
+
+  child_range children() { return child_range(&Evt, &Evt + 1); }
+
+  const_child_range children() const {
+return const_child_range(&Evt, &Evt + 1);
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == OMPC_detach;
+  }
+};
+
 /// This class implements a simple visitor for OMPClause
 /// subclasses.
 template class Ptr, typename RetTy>

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index ce66eeef7a82..27a0bc774184 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3488,6 +3488,12 @@ bool 
RecursiveASTVisitor::VisitOMPOrderClause(OMPOrderClause *) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPDetachClause(OMPDetachClause *C) {
+  TRY_TO(TraverseStmt(C->getEventHandler()));
+  return true;
+}
+
 // FIXME: look at the following tricky-seeming exprs to see if we
 // need to recurse on anything.  These are ones that have methods
 // returning decls or qualtypes or nestednamespecifier -- though I'm

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 77df05fbaf05..a11365130734 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9976,9 +9976,9 @@ def err_omp_wrong_ordered_loop_count : Error<
   "the parameter of the 'ordered' clause must be greater than or equal to the 
parameter of the 'collapse' clause">;
 def note_collapse_loop_count : Note<
   "parameter of the 'collapse' clause">;
-def err_omp_grainsize_num_tasks_mutually_exclusive : Error<
+def err_omp_clauses_mutually_exclusive : Error<
   "'%0' and '%1' clause are mutually exclusive and may 

[PATCH] D76130: [PPC][AIX] Implement variadic function handling in LowerFormalArguments_AIX in 32-bit mode.

2020-03-17 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 250749.
ZarkoCA added a comment.

- Removed 64BIT support varargs.
- Added a fatal error for 64bit varargs on AIX.
- Removed 64bit testcases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76130

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aix-vararg.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/aix-cc-abi-va_args-32.ll
  llvm/test/CodeGen/PowerPC/aix-cc-abi.ll

Index: llvm/test/CodeGen/PowerPC/aix-cc-abi.ll
===
--- llvm/test/CodeGen/PowerPC/aix-cc-abi.ll
+++ llvm/test/CodeGen/PowerPC/aix-cc-abi.ll
@@ -1745,6 +1745,335 @@
 ; ASM64PWR-DAG:li [[REGB]], 1
 ; ASM64PWR-DAG:bl .test_i1
 
+; ASM32PWR4:   add 3, 3, 4
+; ASM32PWR4-DAG:   lwz [[REG1:[0-9]+]], 60(1)
+; ASM32PWR4-DAG:   add 3, 3, 5
+; ASM32PWR4-DAG:   add 3, 3, 6
+; ASM32PWR4-DAG:   add 3, 3, 7
+; ASM32PWR4-DAG:   lwz [[REG2:[0-9]+]], 64(1)
+; ASM32PWR4-DAG:   add 3, 3, 8
+; ASM32PWR4-DAG:   add 3, 3, 9
+; ASM32PWR4-DAG:   lwz [[REG3:[0-9]+]], 68(1)
+; ASM32PWR4-DAG:   add 3, 3, 10
+; ASM32PWR4-DAG:   add 3, 3, [[REG1]]
+; ASM32PWR4-DAG:   add 3, 3, [[REG2]]
+; ASM32PWR4-DAG:   lwz [[REG4:[0-9]+]], 72(1)
+; ASM32PWR4-DAG:   add 3, 3, [[REG3]]
+; ASM32PWR4-DAG:   lwz [[REG5:[0-9]+]], 76(1)
+; ASM32PWR4-DAG:   add 3, 3, [[REG4]]
+; ASM32PWR4-DAG:   lwz [[REG6:[0-9]+]], 84(1)
+; ASM32PWR4-DAG:   add 3, 3, [[REG5]]
+; ASM32PWR4-DAG:   lwz [[REG7:[0-9]+]], 88(1)
+; ASM32PWR4-DAG:   add 3, 3, [[REG6]]
+; ASM32PWR4-DAG:   lwz [[REG8:[0-9]+]], 92(1)
+; ASM32PWR4-DAG:   add 3, 3, [[REG7]]
+; ASM32PWR4-DAG:   add 3, 3, [[REG8]]
+
+; ASM64PWR4-DAG:   ld [[REG1:[0-9]+]], 112(1)
+; ASM64PWR4-DAG:   lwz [[REG2:[0-9]+]], 124(1)
+; ASM64PWR4-DAG:   lwz [[REG3:[0-9]+]], 132(1)
+; ASM64PWR4-DAG:   lwz [[REG4:[0-9]+]], 140(1)
+; ASM64PWR4-DAG:   lwa [[REG5:[0-9]+]], 148(1)
+; ASM64PWR4-DAG:   ld [[REG6:[0-9]+]], 152(1)
+; ASM64PWR4-DAG:   lwz [[REG7:[0-9]+]], 164(1)
+; ASM64PWR4-DAG:   lwa [[REG8:[0-9]+]], 172(1)
+
+@ll1 = common global i64 0, align 8
+@si1 = common global i16 0, align 2
+@ch = common global i8 0, align 1
+@ui = common global i32 0, align 4
+@sint = common global i32 0, align 4
+@ll2 = common global i64 0, align 8
+@uc1 = common global i8 0, align 1
+@i1 = common global i32 0, align 4
+
+define void @caller_ints_stack() {
+entry:
+  %0 = load i64, i64* @ll1, align 8
+  %1 = load i16, i16* @si1, align 2
+  %2 = load i8, i8* @ch, align 1
+  %3 = load i32, i32* @ui, align 4
+  %4 = load i32, i32* @sint, align 4
+  %5 = load i64, i64* @ll2, align 8
+  %6 = load i8, i8* @uc1, align 1
+  %7 = load i32, i32* @i1, align 4
+  %call = call i64 @test_ints_stack(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i64 %0, i16 signext %1, i8 zeroext %2, i32 %3, i32 %4, i64 %5, i8 zeroext %6, i32 %7)
+  ret void
+}
+
+; CHECK-LABEL: name: caller_ints_stack
+
+; 32BIT-DAG:   $r3 = LI 1
+; 32BIT-DAG:   $r4 = LI 2
+; 32BIT-DAG:   $r5 = LI 3
+; 32BIT-DAG:   $r6 = LI 4
+; 32BIT-DAG:   $r7 = LI 5
+; 32BIT-DAG:   $r8 = LI 6
+; 32BIT-DAG:   $r9 = LI 7
+; 32BIT-DAG:   $r10 = LI 8
+; 32BIT-DAG:   renamable $r[[REGLL1ADDR:[0-9]+]] = LWZtoc @ll1, $r2 :: (load 4 from got)
+; 32BIT-DAG:   renamable $r[[REGLL1A:[0-9]+]] = LWZ 0, renamable $r[[REGLL1ADDR]] :: (dereferenceable load 4 from @ll1, align 8)
+; 32BIT-DAG:   renamable $r[[REGLL1B:[0-9]+]] = LWZ 4, killed renamable $r[[REGLL1ADDR]] :: (dereferenceable load 4 from @ll1 + 4)
+; 32BIT-DAG:   STW killed renamable $r[[REGLL1A]], 56, $r1 :: (store 4)
+; 32BIT-DAG:   STW killed renamable $r[[REGLL1B]], 60, $r1 :: (store 4)
+; 32BIT-DAG:   renamable $r[[REGSIADDR:[0-9]+]] = LWZtoc @si1, $r2 :: (load 4 from got)
+; 32BIT-DAG:   renamable $r[[REGSI:[0-9]+]] = LHA 0, killed renamable $r[[REGSIADDR]] :: (dereferenceable load 2 from @si1)
+; 32BIT-DAG:   STW killed renamable $r[[REGSI]], 64, $r1 :: (store 4)
+; 32BIT-DAG:   renamable $r[[REGCHADDR:[0-9]+]] = LWZtoc @ch, $r2 :: (load 4 from got)
+; 32BIT-DAG:   renamable $r[[REGCH:[0-9]+]] = LBZ 0, killed renamable $r[[REGCHADDR]] :: (dereferenceable load 1 from @ch)
+; 32BIT-DAG:   STW killed renamable $r[[REGCH]], 68, $r1 :: (store 4)
+; 32BIT-DAG:   renamable $r[[REGUIADDR:[0-9]+]] = LWZtoc @ui, $r2 :: (load 4 from got)
+; 32BIT-DAG:   renamable $r[[REGUI:[0-9]+]] = LWZ 0, killed renamable $r[[REGUIADDR]] :: (dereferenceable load 4 from @ui)
+; 32BIT-DAG:   STW killed renamable $r[[REGUI]], 72, $r1 :: (store 4)
+; 32BIT-DAG:   renamable $r[[REGSIADDR:[0-9]+]] = LWZtoc @sint, $r2 :: (load 4 from got)
+; 32BIT-DAG:   renamable $r[[REGSI:[0-9]+]] = LWZ 0, killed renamable $r[[REGSIADDR]] :: (dereferenceable load 4 from @sint)
+; 32BIT-DAG:   STW killed renamable $r[[REGSI]], 76, $r1 :: (store 4)
+; 32BIT-DAG:   renamable $r[[REGLL2ADDR:[0-9]+]] = LWZtoc @ll2, $r2 :: (load 4 from got)
+; 32BIT-DAG:   renamable 

[PATCH] D76229: [clang-tidy] Added PlacementNewStorageCheck

2020-03-17 Thread Karasev Nikita via Phabricator via cfe-commits
f00kat added a comment.

NoQ, I don`t want to say that existing static alalyzer is bad written or 
something. I just noticed that it does not yet support arrays and alignment.
Anyway thank you for your detailed feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76229



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


[clang] acf6e41 - Purge unused diagnostics. NFC.

2020-03-17 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2020-03-17T15:17:10+01:00
New Revision: acf6e4190f401d8da5ab0ff5e350db3c8fb18dfe

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

LOG: Purge unused diagnostics. NFC.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index f22d3a18d254..acb229225ea1 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -26,8 +26,6 @@ def err_msasm_unable_to_create_target : Error<
   "MS-style inline assembly is not available: %0">;
 def err_gnu_inline_asm_disabled : Error<
   "GNU-style inline assembly is disabled">;
-def err_asm_goto_cannot_have_output : Error<
-  "'asm goto' cannot have output constraints">;
 def err_asm_duplicate_qual : Error<"duplicate asm qualifier '%0'">;
 }
 
@@ -181,9 +179,6 @@ def err_unparenthesized_non_primary_expr_in_requires_clause 
: Error<
   "parentheses are required around this expression in a requires clause">;
 def note_unparenthesized_non_primary_expr_in_requires_clause : Note<
   "parentheses are required around this expression in a requires clause">;
-def err_potential_function_call_in_constraint_logical_or : Error<
-  "function call must be parenthesized to be considered part of the requires "
-  "clause">;
 
 def err_expected_fn_body : Error<
   "expected function body after function declarator">;
@@ -211,7 +206,6 @@ def err_invalid_token_after_declarator_suggest_equal : 
Error<
   "invalid %0 at end of declaration; did you mean '='?">;
 def err_expected_statement : Error<"expected statement">;
 def err_expected_lparen_after : Error<"expected '(' after '%0'">;
-def err_expected_lbrace_after : Error<"expected '{' after '%0'">;
 def err_expected_rparen_after : Error<"expected ')' after '%0'">;
 def err_expected_punc : Error<"expected ')' or ',' after '%0'">;
 def err_expected_less_after : Error<"expected '<' after '%0'">;
@@ -744,17 +738,10 @@ def err_friend_explicit_instantiation : Error<
 def err_explicit_instantiation_enum : Error<
   "enumerations cannot be explicitly instantiated">;
 def err_expected_template_parameter : Error<"expected template parameter">;
-def note_ill_formed_requires_expression_outside_template : Note<
-  "requires expression outside a template declaration may not contain invalid "
-  "types or expressions">;
 def err_empty_requires_expr : Error<
   "a requires expression must contain at least one requirement">;
 def err_requires_expr_parameter_list_ellipsis : Error<
   "varargs not allowed in requires expression">;
-def err_requires_expr_type_req_illegal_identifier : Error<
-  "expected identifier or template-id in type requirement">;
-def err_requires_expr_type_req_template_args_on_non_template : Error<
-  "template arguments provided for non-template '%0'">;
 def err_expected_semi_requirement : Error<
   "expected ';' at end of requirement">;
 def err_requires_expr_missing_arrow : Error<
@@ -764,9 +751,6 @@ def err_requires_expr_expected_type_constraint : Error<
 def err_requires_expr_simple_requirement_noexcept : Error<
   "'noexcept' can only be used in a compound requirement (with '{' '}' around "
   "the expression)">;
-def err_requires_expr_simple_requirement_unexpected_tok : Error<
-  "unexpected %0 after expression; did you intend to use a compound "
-  "requirement (with '{' '}' around the expression)?">;
 def warn_requires_expr_in_simple_requirement : Warning<
   "this requires expression will only be checked for syntactic validity; did "
   "you intend to place it in a nested requirement? (add another 'requires' "

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a11365130734..7cb1eae9615b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1948,9 +1948,6 @@ def note_destructor_nontype_here : Note<
 def ext_dtor_named_in_wrong_scope : Extension<
   "ISO C++ requires the name after '::~' to be found in the same scope as "
   "the name before '::~'">, InGroup;
-def ext_dtor_name_missing_template_arguments : Extension<
-  "ISO C++ requires template argument list in destructor name">,
-  InGroup;
 def ext_qualified_dtor_named_in_lexical_scope : ExtWarn<
   "qualified destructor name only found in lexical scope; omit the qualifier "
   "to find this type name by unqualified lookup">, InGroup;
@@ -2650,8 +2647,6 @@ def err_concept_extra_headers : Error<
   "extraneous template parameter list in concept definition">;
 def err_concept_no_associated_constraints : Error<
   "concept cannot 

[PATCH] D76283: [IRBuilder] Use preferred target type for len argument of memory intrinsic functions

2020-03-17 Thread Konstantin Schwarz via Phabricator via cfe-commits
kschwarz created this revision.
kschwarz added reviewers: rjmccall, gchatelet, aemerson.
Herald added subscribers: cfe-commits, jfb.
Herald added a project: clang.

The IR builder hard-coded the type of the `len` argument of the memory function 
instrinsics to i64 for several builder functions.

During instruction selection of these intrinsics to the corresponding C library 
functions SelectionDAG ignores the type of the len argument and uses the 
targets preferred type.
GlobalISel however translates these calls using the actual types of the 
intrinsic, which will miscompile on 32-bit architectures.

Using the preferred type when creating the intrinsic call in the first place 
fixes this issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76283

Files:
  clang/test/CodeGen/c11atomics-ios.c
  clang/test/CodeGen/c11atomics.c
  clang/test/CodeGen/x86-atomic-long_double.c
  clang/test/CodeGenCXX/pod-member-memcpys.cpp
  clang/test/CodeGenCXX/pr20897.cpp
  llvm/include/llvm/IR/IRBuilder.h
  llvm/test/Transforms/MemCpyOpt/form-memset.ll

Index: llvm/test/Transforms/MemCpyOpt/form-memset.ll
===
--- llvm/test/Transforms/MemCpyOpt/form-memset.ll
+++ llvm/test/Transforms/MemCpyOpt/form-memset.ll
@@ -50,7 +50,7 @@
 	ret void
 ; CHECK-LABEL: @test1(
 ; CHECK-NOT: store
-; CHECK: call void @llvm.memset.p0i8.i64
+; CHECK: call void @llvm.memset.p0i8.i32
 ; CHECK-NOT: store
 ; CHECK: ret
 }
@@ -152,11 +152,11 @@
 
 ; CHECK-LABEL: @test2(
 ; CHECK-NOT: store
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 1 %tmp41, i8 -1, i64 8, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 1 %tmp41, i8 -1, i32 8, i1 false)
 ; CHECK-NOT: store
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %0, i8 0, i64 32, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 8 %0, i8 0, i32 32, i1 false)
 ; CHECK-NOT: store
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %1, i8 0, i64 32, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 8 %1, i8 0, i32 32, i1 false)
 ; CHECK-NOT: store
 ; CHECK: ret
 }
@@ -175,7 +175,7 @@
   ret void
 ; CHECK-LABEL: @test3(
 ; CHECK-NOT: store
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 4 %1, i8 0, i64 15, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %1, i8 0, i32 15, i1 false)
 }
 
 ; store followed by memset, different offset scenario
@@ -188,7 +188,7 @@
   ret void
 ; CHECK-LABEL: @test4(
 ; CHECK-NOT: store
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 4 %1, i8 0, i64 15, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %1, i8 0, i32 15, i1 false)
 }
 
 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
@@ -204,7 +204,7 @@
   ret void
 ; CHECK-LABEL: @test5(
 ; CHECK-NOT: store
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 4 %1, i8 0, i64 15, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %1, i8 0, i32 15, i1 false)
 }
 
 ;; Memset followed by memset.
@@ -217,7 +217,7 @@
   tail call void @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 12, i1 false)
   ret void
 ; CHECK-LABEL: @test6(
-; CHECK: call void @llvm.memset.p0i8.i64(i8* %2, i8 0, i64 24, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* %2, i8 0, i32 24, i1 false)
 }
 
 ; More aggressive heuristic
@@ -233,7 +233,7 @@
   %4 = getelementptr inbounds i32, i32* %c, i32 4
   store i32 -1, i32* %4, align 4
 ; CHECK-LABEL: @test7(
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 4 %5, i8 -1, i64 20, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %5, i8 -1, i32 20, i1 false)
   ret void
 }
 
@@ -270,7 +270,7 @@
   store i8 -1, i8* getelementptr (i8, i8* bitcast ([16 x i64]* @test9buf to i8*), i64 15), align 1
   ret void
 ; CHECK-LABEL: @test9(
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 16 bitcast ([16 x i64]* @test9buf to i8*), i8 -1, i64 16, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 16 bitcast ([16 x i64]* @test9buf to i8*), i8 -1, i32 16, i1 false)
 }
 
 ; PR19092
@@ -280,7 +280,7 @@
   ret void
 ; CHECK-LABEL: @test10(
 ; CHECK-NOT: memset
-; CHECK: call void @llvm.memset.p0i8.i64(i8* %P, i8 0, i64 42, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* %P, i8 0, i32 42, i1 false)
 ; CHECK-NOT: memset
 ; CHECK: ret void
 }
@@ -297,7 +297,7 @@
   ret void
 ; CHECK-LABEL: @test11(
 ; CHECK-NOT: store
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 4 %1, i8 1, i64 23, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %1, i8 1, i32 23, i1 false)
 }
 
 ; Alignment should be preserved when there is a store with default align
@@ -310,5 +310,5 @@
   ret void
 ; CHECK-LABEL: @test12(
 ; CHECK-NOT: store
-; CHECK: call void @llvm.memset.p0i8.i64(i8* align 4 %1, i8 0, i64 15, i1 false)
+; CHECK: call void @llvm.memset.p0i8.i32(i8* align 4 %1, i8 0, i32 15, i1 false)
 }
Index: llvm/include/llvm/IR/IRBuilder.h

[PATCH] D69330: [AST] Add RecoveryExpr to retain expressions on semantic errors

2020-03-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 250765.
hokein added a comment.
Herald added a subscriber: martong.

- rebase to master, fix more broken tests
  - preferType in CodeCompletTest
  - openMP diagnostics target_update_from_messages.cpp, 
target_update_to_messages.cpp
- RecoveryExpression RValue => LValue
- Fix a NULL assertion crash on gnu conditional operator ?:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69330

Files:
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/AST/ast-dump-expr-errors.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/Index/getcursor-recovery.cpp
  clang/test/Modules/submodules-merge-defs.cpp
  clang/test/OpenMP/target_update_from_messages.cpp
  clang/test/OpenMP/target_update_to_messages.cpp
  clang/test/Parser/objcxx0x-lambda-expressions.mm
  clang/test/Parser/objcxx11-invalid-lambda.cpp
  clang/test/SemaCXX/builtins.cpp
  clang/test/SemaCXX/cast-conversion.cpp
  clang/test/SemaCXX/cxx1z-copy-omission.cpp
  clang/test/SemaCXX/decltype-crash.cpp
  clang/test/SemaCXX/varargs.cpp
  clang/test/SemaOpenCLCXX/address-space-references.cl
  clang/test/SemaTemplate/instantiate-init.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/unittests/Sema/CodeCompleteTest.cpp

Index: clang/unittests/Sema/CodeCompleteTest.cpp
===
--- clang/unittests/Sema/CodeCompleteTest.cpp
+++ clang/unittests/Sema/CodeCompleteTest.cpp
@@ -487,6 +487,8 @@
 auto x = decltype(&1)(^);
 auto y = new decltype(&1)(^);
   )cpp";
-  EXPECT_THAT(collectPreferredTypes(Code), Each("NULL TYPE"));
+  EXPECT_THAT(collectPreferredTypes(Code),
+  Each("decltype((1))"));
 }
+
 } // namespace
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -292,6 +292,7 @@
   case Stmt::ObjCDictionaryLiteralClass:
   case Stmt::ObjCBoxedExprClass:
   case Stmt::ObjCSubscriptRefExprClass:
+  case Stmt::RecoveryExprClass:
 K = CXCursor_UnexposedExpr;
 break;
 
Index: clang/test/SemaTemplate/instantiate-init.cpp
===
--- clang/test/SemaTemplate/instantiate-init.cpp
+++ clang/test/SemaTemplate/instantiate-init.cpp
@@ -100,7 +100,7 @@
 integral_c<1> ic1 = array_lengthof(Description::data);
 (void)sizeof(array_lengthof(Description::data));
 
-sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
+(void)sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
   Description::data // expected-note{{in instantiation of static data member 'PR7985::Description::data' requested here}}
   ));
 
Index: clang/test/SemaOpenCLCXX/address-space-references.cl
===
--- clang/test/SemaOpenCLCXX/address-space-references.cl
+++ clang/test/SemaOpenCLCXX/address-space-references.cl
@@ -11,7 +11,7 @@
 int bar(const unsigned int &i);
 
 void foo() {
-  bar(1) // expected-error{{binding reference of type 'const __global unsigned int' to value of type 'int' changes address space}}
+  bar(1); // expected-error{{binding reference of type 'const __global unsigned int' to value of type 'int' changes address space}}
 }
 
 // Test addr space conversion with nested pointers
Index: clang/test/SemaCXX/varargs.cpp
===
--- clang/test/SemaCXX/varargs.cpp
+++ clang/test/SemaCXX/varargs.cpp
@@ -22,7 +22,8 @@
 // default ctor.
 void record_context(int a, ...) {
   struct Foo {
-// expected-error@+1 {{'va_start' cannot be used outside a function}}
+// expected-error@+2 {{'va_start' cannot be used outside a function}}
+// expected-error@+1 {{default argument references parameter 'a'}}
 void meth(int a, int b = (__builtin_va_start(ap, a), 0)) {}
   };
 }
Index: clang/test/SemaCXX/decltype-crash.cpp
==

[PATCH] D76283: [IRBuilder] Use preferred target type for len argument of memory intrinsic functions

2020-03-17 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

So what happens if i manually create such IR, or create such IR without using 
IRBuilder?
It will again compile fine via SelectionDAG and will be miscompiled via 
GlobalISel, correct?
Don't you then want to harden `-verify` to barf on such mismatch, too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76283



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


[PATCH] D74541: [Analyzer] Use note tags to track iterator increments and decrements

2020-03-17 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added inline comments.
Herald added a subscriber: DenisDvlp.



Comment at: clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp:489-490
+StringRef ChangeText =
+  ((Op == OO_Plus || Op == OO_PlusEqual) != (ChangeVal <= 0)) ?
+  "incremented" : "decremented";
+const NoteTag *ChangeTag = getChangeTag(C, ChangeText, ItE,

NoQ wrote:
> NoQ wrote:
> > Can we assert out the `ChangeVal == 0` case or make a better message for it 
> > (`"unchanged"` or something like that)?
> Another important thing to do here is to track the RHS value via 
> `trackExpressionValue()`. I.e., why do we think that iterator is incremented 
> by 1 and not by 2?
I agree, that is important, but where should I call it? This is the modeling 
checker, which models the increments and the decrements, but 
`trackExpressionValue()` can only be invoked for bug reports. Should I put it 
into the `NoteTag` lambda?


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

https://reviews.llvm.org/D74541



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


[PATCH] D75169: [ARM] Enforcing calling convention for half-precision FP arguments and returns for big-endian AArch32

2020-03-17 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas added a comment.

Hi @rjmccall,
I agree those kind of tweaks do not look good. The issue here, though, is that 
argument coercion currently ignores the target's endian information when 
performing coercion through memory.
This happens for any type that requires memory coercion, so unfortunately using 
`[1 x i32]` does not do the trick.
Let me know if you have any other sugestions for handling this, I'd be glad to 
avoid the `ABIArgInfo` approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75169



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


[PATCH] D73891: [RISCV] Support experimental/unratified extensions

2020-03-17 Thread Simon Cook via Phabricator via cfe-commits
simoncook updated this revision to Diff 250770.
simoncook added a comment.

- Update to match latest dependencies
- Handle adding "experimental-" to SubtargetFeatures for experimental features


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73891

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c

Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -264,20 +264,20 @@
 // RV32-IMINOR1: error: invalid arch name 'rv32i2p1', unsupported
 // RV32-IMINOR1: version number 2.1 for extension 'i'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32ix2p -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ixt2p -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XMINOR-MISS %s
-// RV32-XMINOR-MISS: error: invalid arch name 'rv32ix2p',
-// RV32-XMINOR-MISS: minor version number missing after 'p' for extension 'x2p'
+// RV32-XMINOR-MISS: error: invalid arch name 'rv32ixt2p',
+// RV32-XMINOR-MISS: minor version number missing after 'p' for extension 'xt'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32is2p0 -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ist2p0 -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-SMINOR0 %s
-// RV32-SMINOR0: error: invalid arch name 'rv32is2p0',
-// RV32-SMINOR0: unsupported version number 2.0 for extension 's2p0'
+// RV32-SMINOR0: error: invalid arch name 'rv32ist2p0',
+// RV32-SMINOR0: unsupported version number 2.0 for extension 'st'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32isx2p1 -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32isxt2p1 -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-SXMINOR1 %s
-// RV32-SXMINOR1: error: invalid arch name 'rv32isx2p1', unsupported
-// RV32-SXMINOR1: version number 2.1 for extension 'sx2p1'
+// RV32-SXMINOR1: error: invalid arch name 'rv32isxt2p1', unsupported
+// RV32-SXMINOR1: version number 2.1 for extension 'sxt'
 
 // RUN: %clang -target riscv32-unknown-elf -march=rv32ixabc_ -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
@@ -327,3 +327,36 @@
 // RUN: %clang -target riscv64-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RV64-TARGET: "-triple" "riscv64-unknown-unknown-elf"
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOFLAG %s
+// RV32-EXPERIMENTAL-NOFLAG: error: invalid arch name 'rv32ib'
+// RV32-EXPERIMENTAL-NOFLAG: requires '-menable-experimental-extensions'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOVERS %s
+// RV32-EXPERIMENTAL-NOVERS: error: invalid arch name 'rv32ib'
+// RV32-EXPERIMENTAL-NOVERS: experimental extension requires explicit version number
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p1 -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS %s
+// RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32ib0p1'
+// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental extension
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p92 -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-GOODVERS %s
+// RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-b"
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB-NOFLAG %s
+// RV32-EXPERIMENTAL-ZBB-NOFLAG: error: invalid arch name 'rv32izbb'
+// RV32-EXPERIMENTAL-ZBB-NOFLAG: requires '-menable-experimental-extensions'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92 -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB %s
+// RV32-EXPERIMENTAL-ZBB: "-target-feature" "+experimental-zbb"
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92_zbp0p92 -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP %s
+// RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbb"
+// RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbp"
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -22,6 +22,14 @@
 using namespace clang;
 using namespace llvm::opt;
 
+namespace {

[PATCH] D71553: [RISCV] Add Clang frontend support for Bitmanip extension

2020-03-17 Thread Simon Cook via Phabricator via cfe-commits
simoncook updated this revision to Diff 250771.
simoncook added a comment.
Herald added a subscriber: evandro.

Rebase on new dependencies


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71553

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/test/Preprocessor/riscv-target-features.c


Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -7,6 +7,7 @@
 // CHECK-NOT: __riscv_mul
 // CHECK-NOT: __riscv_muldiv
 // CHECK-NOT: __riscv_compressed
+// CHECK-NOT: __riscv_bitmanip
 // CHECK-NOT: __riscv_flen
 // CHECK-NOT: __riscv_fdiv
 // CHECK-NOT: __riscv_fsqrt
@@ -48,6 +49,12 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
 // CHECK-C-EXT: __riscv_compressed 1
 
+// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions -march=rv32ib0p92 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions -march=rv64ib0p92 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// CHECK-B-EXT: __riscv_bitmanip 1
+
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32 -x 
c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-SOFT %s
 // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -mabi=lp64 -x 
c -E -dM %s \
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -30,11 +30,12 @@
   bool HasF;
   bool HasD;
   bool HasC;
+  bool HasB;
 
 public:
   RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
   : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
-HasD(false), HasC(false) {
+HasD(false), HasC(false), HasB(false) {
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -125,6 +125,10 @@
 
   if (HasC)
 Builder.defineMacro("__riscv_compressed");
+
+  if (HasB) {
+Builder.defineMacro("__riscv_bitmanip");
+  }
 }
 
 /// Return true if has this feature, need to sync with handleTargetFeatures.
@@ -139,6 +143,7 @@
   .Case("f", HasF)
   .Case("d", HasD)
   .Case("c", HasC)
+  .Case("experimental-b", HasB)
   .Default(false);
 }
 
@@ -156,6 +161,8 @@
   HasD = true;
 else if (Feature == "+c")
   HasC = true;
+else if (Feature == "+experimental-b")
+  HasB = true;
   }
 
   return true;


Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -7,6 +7,7 @@
 // CHECK-NOT: __riscv_mul
 // CHECK-NOT: __riscv_muldiv
 // CHECK-NOT: __riscv_compressed
+// CHECK-NOT: __riscv_bitmanip
 // CHECK-NOT: __riscv_flen
 // CHECK-NOT: __riscv_fdiv
 // CHECK-NOT: __riscv_fsqrt
@@ -48,6 +49,12 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
 // CHECK-C-EXT: __riscv_compressed 1
 
+// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32ib0p92 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64ib0p92 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// CHECK-B-EXT: __riscv_bitmanip 1
+
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-SOFT %s
 // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -mabi=lp64 -x c -E -dM %s \
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -30,11 +30,12 @@
   bool HasF;
   bool HasD;
   bool HasC;
+  bool HasB;
 
 public:
   RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
   : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
-HasD(false), HasC(false) {
+HasD(false), HasC(false), HasB(false) {
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -125,6 +125,10 @@
 
   if (HasC)
 Builder.defineMacro("

[PATCH] D76130: [PPC][AIX] Implement variadic function handling in LowerFormalArguments_AIX in 32-bit mode.

2020-03-17 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA updated this revision to Diff 250772.
ZarkoCA added a comment.

Removed unrelated changes in aix-cc-abi.ll


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

https://reviews.llvm.org/D76130

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aix-vararg.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/aix-cc-abi-va_args-32.ll

Index: llvm/test/CodeGen/PowerPC/aix-cc-abi-va_args-32.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-cc-abi-va_args-32.ll
@@ -0,0 +1,277 @@
+; RUN: llc -O2 -mtriple powerpc-ibm-aix-xcoff -stop-after=machine-cp -mattr=-altivec -verify-machineinstrs < %s | \
+; RUN: FileCheck --check-prefixes=CHECK,32BIT %s
+
+; RUN: llc -O2 -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec \
+; RUN:  -mtriple powerpc-ibm-aix-xcoff < %s | \
+; RUN: FileCheck --check-prefixes=CHECKASM,ASM32PWR4 %s
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
+
+; Function Attrs: nounwind
+declare void @llvm.va_start(i8*) #2
+
+; Function Attrs: nounwind
+declare void @llvm.va_end(i8*) #2
+declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1
+
+@a = local_unnamed_addr global i32 1, align 4
+@b = local_unnamed_addr global i32 2, align 4
+@c = local_unnamed_addr global i32 3, align 4
+@d = local_unnamed_addr global i32 4, align 4
+@e = local_unnamed_addr global i32 5, align 4
+@f = local_unnamed_addr global i32 6, align 4
+@g = local_unnamed_addr global i32 7, align 4
+@h = local_unnamed_addr global i32 8, align 4
+@i = local_unnamed_addr global i32 9, align 4
+@j = local_unnamed_addr global i32 10, align 4
+
+; Function Attrs: nounwind
+define i32 @va_arg1(i32 %a, ...) local_unnamed_addr #0 {
+entry:
+  %arg = alloca i8*, align 4
+  %0 = bitcast i8** %arg to i8*
+  call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #2
+  call void @llvm.va_start(i8* nonnull %0)
+  %cmp7 = icmp sgt i32 %a, 0
+  br i1 %cmp7, label %for.body.preheader, label %for.end
+
+for.body.preheader:   ; preds = %entry
+  %argp.cur.pre = load i8*, i8** %arg, align 4
+  %min.iters.check = icmp eq i32 %a, 1
+  br i1 %min.iters.check, label %for.body.preheader15, label %vector.memcheck
+
+vector.memcheck:  ; preds = %for.body.preheader
+  %uglygep = getelementptr inbounds i8, i8* %0, i32 1
+  %1 = shl i32 %a, 2
+  %scevgep = getelementptr i8, i8* %argp.cur.pre, i32 %1
+  %bound0 = icmp ugt i8* %scevgep, %0
+  %bound1 = icmp ult i8* %argp.cur.pre, %uglygep
+  %found.conflict = and i1 %bound0, %bound1
+  br i1 %found.conflict, label %for.body.preheader15, label %vector.ph
+
+vector.ph:; preds = %vector.memcheck
+  %n.vec = and i32 %a, -2
+  %2 = shl i32 %n.vec, 2
+  %ind.end = getelementptr i8, i8* %argp.cur.pre, i32 %2
+  br label %vector.body
+
+vector.body:  ; preds = %vector.body, %vector.ph
+  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
+  %vec.phi = phi i32 [ undef, %vector.ph ], [ %11, %vector.body ]
+  %vec.phi13 = phi i32 [ 0, %vector.ph ], [ %12, %vector.body ]
+  %3 = shl i32 %index, 2
+  %next.gep = getelementptr i8, i8* %argp.cur.pre, i32 %3
+  %4 = shl i32 %index, 2
+  %5 = or i32 %4, 4
+  %next.gep12 = getelementptr i8, i8* %argp.cur.pre, i32 %5
+  %6 = getelementptr inbounds i8, i8* %next.gep12, i32 4
+  %7 = bitcast i8* %next.gep to i32*
+  %8 = bitcast i8* %next.gep12 to i32*
+  %9 = load i32, i32* %7, align 4 
+  %10 = load i32, i32* %8, align 4
+  %11 = add i32 %9, %vec.phi
+  %12 = add i32 %10, %vec.phi13
+  %index.next = add i32 %index, 2
+  %13 = icmp eq i32 %index.next, %n.vec
+  br i1 %13, label %middle.block, label %vector.body
+
+middle.block: ; preds = %vector.body
+  store i8* %6, i8** %arg, align 4
+  %bin.rdx = add i32 %12, %11
+  %cmp.n = icmp eq i32 %n.vec, %a
+  br i1 %cmp.n, label %for.end, label %for.body.preheader15
+
+for.body.preheader15: ; preds = %middle.block, %vector.memcheck, %for.body.preheader
+  %argp.cur.ph = phi i8* [ %argp.cur.pre, %vector.memcheck ], [ %argp.cur.pre, %for.body.preheader ], [ %ind.end, %middle.block ]
+  %total.09.ph = phi i32 [ undef, %vector.memcheck ], [ undef, %for.body.preheader ], [ %bin.rdx, %middle.block ]
+  %i.08.ph = phi i32 [ 0, %vector.memcheck ], [ 0, %for.body.preheader ], [ %n.vec, %middle.block ]
+  br label %for.body
+
+for.body: ; preds = %for.body.preheader15, %for.body
+  %argp.cur = phi i8* [ %argp.next, %for.body ], [ %argp.cur.ph, %for.body.preheader15 ]
+  %total.09 = phi i32 [ %add, %for.body ], [ %total.09.ph, %for.body.preheader15 ]
+  %i.08 = phi i32 [ %inc, %for.body ], [ %i.08.ph, %for.body.preheader15 ]
+  %argp.next = getelementptr inbounds 

[PATCH] D76229: [clang-tidy] Added PlacementNewStorageCheck

2020-03-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Sure np, was just curious^^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76229



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


[PATCH] D75687: [clangd] Only minimally escape text when rendering to markdown.

2020-03-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks, still LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75687



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


[clang] 60963fa - [HIP] Let clang recognize .hip extension

2020-03-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-03-17T11:22:55-04:00
New Revision: 60963fa630126f5a4554088e85ddaf8fff286cef

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

LOG: [HIP] Let clang recognize .hip extension

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

Added: 
clang/test/CodeGenCUDA/hip-pinned-shadow.hip

Modified: 
clang/lib/Frontend/FrontendOptions.cpp
clang/test/Driver/hip-autolink.hip
clang/test/Driver/hip-default-gpu-arch.hip
clang/test/Driver/hip-device-libs.hip
clang/test/Driver/hip-host-cpu-features.hip
clang/test/Driver/hip-no-device-libs.hip
clang/test/Driver/hip-output-file-name.hip
clang/test/Driver/hip-printf.hip
clang/test/Driver/hip-save-temps.hip
clang/test/Driver/hip-syntax-only.hip
clang/test/Driver/hip-toolchain-features.hip
clang/test/Driver/hip-toolchain-mllvm.hip
clang/test/Driver/hip-toolchain-opt.hip

Removed: 
clang/test/CodeGenCUDA/hip-pinned-shadow.cu



diff  --git a/clang/lib/Frontend/FrontendOptions.cpp 
b/clang/lib/Frontend/FrontendOptions.cpp
index 5c1fbf889c23..63088b95c310 100644
--- a/clang/lib/Frontend/FrontendOptions.cpp
+++ b/clang/lib/Frontend/FrontendOptions.cpp
@@ -30,6 +30,7 @@ InputKind FrontendOptions::getInputKindForExtension(StringRef 
Extension) {
   .Case("iim", InputKind(Language::CXX).getPreprocessed())
   .Case("cl", Language::OpenCL)
   .Case("cu", Language::CUDA)
+  .Case("hip", Language::HIP)
   .Cases("ll", "bc", Language::LLVM_IR)
   .Default(Language::Unknown);
 }

diff  --git a/clang/test/CodeGenCUDA/hip-pinned-shadow.cu 
b/clang/test/CodeGenCUDA/hip-pinned-shadow.hip
similarity index 81%
rename from clang/test/CodeGenCUDA/hip-pinned-shadow.cu
rename to clang/test/CodeGenCUDA/hip-pinned-shadow.hip
index 1d22ed6dc94c..7f0e7544d828 100644
--- a/clang/test/CodeGenCUDA/hip-pinned-shadow.cu
+++ b/clang/test/CodeGenCUDA/hip-pinned-shadow.hip
@@ -1,11 +1,11 @@
 // REQUIRES: amdgpu-registered-target
 
 // RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 -fvisibility 
hidden -fapply-global-visibility-to-externs \
-// RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPDEV %s
+// RUN: -emit-llvm -o - %s | FileCheck -check-prefixes=HIPDEV %s
 // RUN: %clang_cc1 -triple x86_64 -std=c++11 \
-// RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPHOST %s
+// RUN: -emit-llvm -o - %s | FileCheck -check-prefixes=HIPHOST %s
 // RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 -fvisibility 
hidden -fapply-global-visibility-to-externs \
-// RUN: -O3 -emit-llvm -o - -x hip %s | FileCheck 
-check-prefixes=HIPDEVUNSED %s
+// RUN: -O3 -emit-llvm -o - %s | FileCheck -check-prefixes=HIPDEVUNSED %s
 
 struct textureReference {
   int a;

diff  --git a/clang/test/Driver/hip-autolink.hip 
b/clang/test/Driver/hip-autolink.hip
index 9c1b65f1592b..c06f0f9d8b71 100644
--- a/clang/test/Driver/hip-autolink.hip
+++ b/clang/test/Driver/hip-autolink.hip
@@ -3,9 +3,9 @@
 // REQUIRES: amdgpu-registered-target
 //
 // RUN: %clang --target=i386-pc-windows-msvc --cuda-gpu-arch=gfx906 -nogpulib \
-// RUN:   --cuda-device-only -x hip %s -### 2>&1 | FileCheck 
--check-prefix=DEV %s
+// RUN:   --cuda-device-only %s -### 2>&1 | FileCheck --check-prefix=DEV %s
 // RUN: %clang --target=i386-pc-windows-msvc --cuda-gpu-arch=gfx906 -nogpulib \
-// RUN:   --cuda-host-only -x hip %s -### 2>&1 | FileCheck --check-prefix=HOST 
%s
+// RUN:   --cuda-host-only %s -### 2>&1 | FileCheck --check-prefix=HOST %s
 
 // DEV: "-cc1" "-triple" "amdgcn-amd-amdhsa"
 // DEV-SAME: "-fno-autolink"

diff  --git a/clang/test/Driver/hip-default-gpu-arch.hip 
b/clang/test/Driver/hip-default-gpu-arch.hip
index 56e36882dc63..bce9a67b4b1c 100644
--- a/clang/test/Driver/hip-default-gpu-arch.hip
+++ b/clang/test/Driver/hip-default-gpu-arch.hip
@@ -2,6 +2,6 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang -### -x hip -c %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c %s 2>&1 | FileCheck %s
 
 // CHECK: {{.*}}clang{{.*}}"-target-cpu" "gfx803"

diff  --git a/clang/test/Driver/hip-device-libs.hip 
b/clang/test/Driver/hip-device-libs.hip
index 97e76525dde8..b79cb70cbe68 100644
--- a/clang/test/Driver/hip-device-libs.hip
+++ b/clang/test/Driver/hip-device-libs.hip
@@ -5,7 +5,7 @@
 // Test flush-denormals-to-zero enabled uses oclc_daz_opt_on
 
 // RUN: %clang -### -target x86_64-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   --hip-device-lib-path=%S/Inputs/hip_dev_lib \
 // RUN:   -fcuda-flush-denormals-to-zero \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
@@ -14,7 +14,7 @@
 // Test flush-denormals-to-zero disabled uses oclc_daz_opt_off
 
 // RUN: %clang -### -

[PATCH] D76287: [analysis][analyzer] Introduce the skeleton of a reaching definitions calculator

2020-03-17 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, martong, whisperity, rnkovacs, 
dcoughlin, baloghadamsoftware.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, DenisDvlp, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, szepet, mgorny.

The following revision adds the basic infrastructure for a reaching definitions 
algorithm for C++.

Short description & motivation
==

This is a dataflow algorithm designed to find a set of definitions (for example 
assignments) to variables in a given `CFGBlock`. To demonstrate, in the 
following code snippet:

  int flag;
  
  void foo();
  
  void f() {
int *x = nullptr;
flag = 1;
  
foo();
if (flag)
  x = new int;
  
foo();
if (flag)
  *x = 5;
  }

The CFG would look like this:

  
 -> [B3] ->-> [B1] ->
/  \  /  \
  [B5 (ENTRY)] -> [B4] --> [B2] ---> [B0 (EXIT)]

Should `foo()` change `flag`'s value on the first function call to `false`, 
then `true` on the second, a null pointer dereference error would occur. Using 
a reaching definitions calculator, we can retrieve that the set of ingoing 
definitions to B1  is `{(flag, [B2]), (x, [B3]), 
(x, [B4])}`. The set hints that `x` has a reaching definitions that would not 
have caused a nullpointer dereference.

The algorithm
=

A reaching definition for a given instruction is an earlier instruction whose 
target variable can reach (be assigned to) the given one without an intervening 
assignment. The similarly named reaching definitions is a data-flow analysis 
which statically determines which definitions may reach a given point in the 
code [1].

The set of ingoing and outgoing reaching definitions are calculated for each 
basic block with set operations on GEN and KILL sets. This could be further 
fine-grained so the RD sets would be a property of a statement, rather then an 
entire `CFGBlock`, but I didn't want to delay the publishing of this patch any 
further, and I believe that such a change wouldn't hurt the infrastructure much.

Implementation
==

As the formal definition would suggest, this was conceived for instructions, 
which is why even such terms as "variable" or "definition" can be hard to 
define for C++. For this reason, the patch spares a lot of LOC for 
documentation and reasoning. While the algorithm itself is simple (and is 
implemented quite literally from [1]), the problematic part of this is the 
generation of of GEN and KILL sets. I tried to introduce an infrastructure that 
can tolerate a lot of things I have inevitable forgotten (or left for followup 
patches) with the use of easy to add AST matchers.

Immediate questions to address
==

> We already have 2 dataflow algorithms implemented in the Analysis library: 
> UninitializedObject and LiveVariables. Reaching definitions doesn't sound all 
> too dissimilar. Why are we adding hundreds of LOC here? Can't we reuse some 
> of it?

UninitializedObject and LiveVariables are practically the same algorithm with 
minimal differences. Despite this, they take up ~750 and ~1050 LOC 
respectively. Both of those algorithms can be expressed with the use of GEN and 
KILL sets, yet none of them are, and they duplicate a lot of logic. It isn't 
terribly obvious however how their logic could be (or really, should be) merged.

Shockingly, we have no GEN and KILL set implementations in Clang. I think that 
is the main addition of this patch, even if it unfortunately duplicates some 
logic. The previously mentioned two analyses however could serve as an 
inspiration.

> UninitializedObject and LiveVariables uses ASTVisitors rather than 
> ASTMatchers. The latter is more expensive. Why did we go with them?

Matchers are more expressive. For instance, how would you find `s.a.x.z` with 
visitors? Its doable, but requires to keep track of a lot of state and would 
make the implementation ugly. I don't have complete confidence in my decision 
here, so I welcome alternative suggestions or counterarguments.

> What are the main things to get done?

In order:

- Finalize the infrastructure for GEN set generation.
- Make it possible to calculate RD sets for statements, not only blocks.
- Improve the interface of `ReachingDefinitionsCalculator`. What we like to 
query? Most probably the set of ingoing RDs for a variable at a given statement.
- Performance: use immutable data structures and a better CFG traversal 
strategy.

Further reading
===

My GSoC project: https://szelethus.github.io/gsoc2019/ (this has a lot of 
pointers to related discussions in the 'Reaching Definitions Analysis' section)

[cfe-dev] Dataflow analyses in Clang -- why do we not have GEN and  KILL 
sets? http://lists.llvm.org/pipermail/cfe-dev/2020-March/064893.html

[analyzer][WIP] Implement a primitive

[PATCH] D71553: [RISCV] Add Clang frontend support for Bitmanip extension

2020-03-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:129
+
+  if (HasB) {
+Builder.defineMacro("__riscv_bitmanip");

delete `{}`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71553



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


[PATCH] D74973: [analyzer] StdLibraryFunctionsChecker refactor w/ inheritance

2020-03-17 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Please have my post-commit approval :^) Nice work!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74973



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


[PATCH] D76289: [NFC][Attr TableGen] Emit Spelling Enum for Attr types if there >1

2020-03-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: aaron.ballman, rnk.

Discovered in a downstream, it is often useful to have slightly
different semantics for an attribute based on its namespace, however our
spelling infrastructure doesn't consider namespace when deciding to
elide the enum list.  The result is that the solution for a case where
an attribute has slightly different semantics based on a namespace
requires checking against the integer value, which is fragile.

  

This patch makes us always emit the spelling enum if there is more than
1 and we're generating the header.


https://reviews.llvm.org/D76289

Files:
  clang/utils/TableGen/ClangAttrEmitter.cpp


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2328,11 +2328,8 @@
 // This maps spelling index values to semantic Spelling enumerants.
 SemanticSpellingMap SemanticToSyntacticMap;
 
-std::string SpellingEnum;
-if (!ElideSpelling)
-  SpellingEnum = CreateSemanticSpellings(Spellings, 
SemanticToSyntacticMap);
-if (Header)
-  OS << SpellingEnum;
+if (Header && Spellings.size() > 1)
+  OS <<  CreateSemanticSpellings(Spellings, SemanticToSyntacticMap);
 
 const auto &ParsedAttrSpellingItr = llvm::find_if(
 AttrMap, [R](const std::pair &P) {


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2328,11 +2328,8 @@
 // This maps spelling index values to semantic Spelling enumerants.
 SemanticSpellingMap SemanticToSyntacticMap;
 
-std::string SpellingEnum;
-if (!ElideSpelling)
-  SpellingEnum = CreateSemanticSpellings(Spellings, SemanticToSyntacticMap);
-if (Header)
-  OS << SpellingEnum;
+if (Header && Spellings.size() > 1)
+  OS <<  CreateSemanticSpellings(Spellings, SemanticToSyntacticMap);
 
 const auto &ParsedAttrSpellingItr = llvm::find_if(
 AttrMap, [R](const std::pair &P) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75682: [Analyzer][StreamChecker] Introduction of stream error handling.

2020-03-17 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Rght I think I finally get it. You don't want to state split on `feof()` 
and `ferror()`, but rather on the stream operations! This is why you only want 
to tell the analyzer what the return value of these functions are going to be, 
because the state of the stream should be set by the time we reach these 
functions, right?

How about untracked streams? What if we call `feof()` on a stream we got from a 
parameter, wouldn't that suggest that the stream is probably non-null and could 
either be EOF or non-EOF?




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:88
 struct FnDescription;
 using FnCheck = std::function;

balazske wrote:
> NoQ wrote:
> > balazske wrote:
> > > NoQ wrote:
> > > > `llvm::function_ref`?
> > > `function_ref`'s documentation says:
> > > > This class does not own the callable, so it is not in general safe to 
> > > > store a function_ref.
> > > The `FnDescription` stores these functions so it is not safe to use 
> > > `llvm::function_ref`?
> > > 
> > > 
> > > 
> > I think you're using it only for global function pointers, no?
> Probably can work but I tried it and got compile errors.
It doesn't matter a whole lot, we could leave this as-is :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75682



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


[PATCH] D76039: [HIP] Let clang recognize .hip extension

2020-03-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG60963fa63012: [HIP] Let clang recognize .hip extension 
(authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D76039?vs=249816&id=250790#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76039

Files:
  clang/lib/Frontend/FrontendOptions.cpp
  clang/test/CodeGenCUDA/hip-pinned-shadow.cu
  clang/test/CodeGenCUDA/hip-pinned-shadow.hip
  clang/test/Driver/hip-autolink.hip
  clang/test/Driver/hip-default-gpu-arch.hip
  clang/test/Driver/hip-device-libs.hip
  clang/test/Driver/hip-host-cpu-features.hip
  clang/test/Driver/hip-no-device-libs.hip
  clang/test/Driver/hip-output-file-name.hip
  clang/test/Driver/hip-printf.hip
  clang/test/Driver/hip-save-temps.hip
  clang/test/Driver/hip-syntax-only.hip
  clang/test/Driver/hip-toolchain-features.hip
  clang/test/Driver/hip-toolchain-mllvm.hip
  clang/test/Driver/hip-toolchain-opt.hip

Index: clang/test/Driver/hip-toolchain-opt.hip
===
--- clang/test/Driver/hip-toolchain-opt.hip
+++ clang/test/Driver/hip-toolchain-opt.hip
@@ -4,56 +4,56 @@
 
 // RUN: %clang -### \
 // RUN:   -target x86_64-unknown-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -c -nogpulib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck --check-prefixes=ALL,DEFAULT %s
 
 // RUN: %clang -### -O0 \
 // RUN:   -target x86_64-unknown-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -c -nogpulib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck --check-prefixes=ALL,O0 %s
 
 // RUN: %clang -### -O1 \
 // RUN:   -target x86_64-unknown-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -c -nogpulib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck --check-prefixes=ALL,O1 %s
 
 // RUN: %clang -### -O2 \
 // RUN:   -target x86_64-unknown-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -c -nogpulib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck --check-prefixes=ALL,O2 %s
 
 // RUN: %clang -### -O3 \
 // RUN:   -target x86_64-unknown-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -c -nogpulib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck --check-prefixes=ALL,O3 %s
 
 // RUN: %clang -### -Os \
 // RUN:   -target x86_64-unknown-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -c -nogpulib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck --check-prefixes=ALL,Os %s
 
 // RUN: %clang -### -Oz \
 // RUN:   -target x86_64-unknown-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -c -nogpulib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck --check-prefixes=ALL,Oz %s
 
 // RUN: %clang -### -Og \
 // RUN:   -target x86_64-unknown-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx900 \
 // RUN:   -c -nogpulib \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck --check-prefixes=ALL,Og %s
Index: clang/test/Driver/hip-toolchain-mllvm.hip
===
--- clang/test/Driver/hip-toolchain-mllvm.hip
+++ clang/test/Driver/hip-toolchain-mllvm.hip
@@ -3,7 +3,7 @@
 // REQUIRES: amdgpu-registered-target
 
 // RUN: %clang -### -target x86_64-linux-gnu \
-// RUN:   -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
 // RUN:   -mllvm -amdgpu-function-calls=0 \
 // RUN:   %s 2>&1 | FileCheck %s
 
Index: clang/test/Driver/hip-toolchain-features.hip
===
--- clang/test/Driver/hip-toolchain-features.hip
+++ clang/test/Driver/hip-toolchain-features.hip
@@ -3,10 +3,10 @@
 // REQUIRES: amdgpu-registered-target
 
 // RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
-// RUN:   -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
+// RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
 // RUN:   -mxnack 2>&1 | FileCheck %s -check-prefix=XNACK
 // RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
-// RUN:   -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
+// RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
 // RUN:   -mno-xnack 2>&1 | FileCheck %s -check-prefix=NOXNACK
 
 // XNACK: {{.*}}clang{{.*}}"-target-feature" "+xnack"
@@ -14,10 +14,10 @@
 
 
 // RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
-// R

[PATCH] D76283: [IRBuilder] Use preferred target type for len argument of memory intrinsic functions

2020-03-17 Thread Konstantin Schwarz via Phabricator via cfe-commits
kschwarz added a comment.

Correct, it will still miscompile even with this change.
I see two options: either 1) extend GlobalISel to select to the appropriate 
type, or 2) declare this as illegal LLVM IR in the first place.

1. will introduce an implicit truncation of the i64 argument (same as 
SelectionDAG does today). In practice this seems to work, but it feels broken
2. I'm not sure whether it should be illegal to create an i64 version of the 
llvm.mem* intrinsics on 32-bit architectures.

Thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76283



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


[PATCH] D76125: [clangd] Decouple preambleworker from astworker, NFCI

2020-03-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This basically looks good, just nits (mostly about comments, sorry I can't help 
myself).

I think the only real outstanding thing is TUStatus, which we're still 
discussing offline. Since this patch is intended to be NFC, I see two paths 
consistent with the spirit of that:

- work out how to make this emit the same sequence of events (probably in a 
fairly brittle way), document that, and sort it out in the next patch
- make TUStatus reflect the new model, without changing its essential design or 
scope. Currently TUStatus is currently (stateful bits about TU, worker thread 
activity), so the extension would be (stateful bits about TU, worker thread 
activity, preamble thread activity).




Comment at: clang-tools-extra/clangd/TUScheduler.cpp:218
+PreambleRequested.wait(Lock, [this] { return PreambleReq || Done; });
+// No request means we are done.
+if (!PreambleReq)

kadircet wrote:
> sammccall wrote:
> > Why do we rebuild the preamble if stop is requested?
> it was to be consistent with astworker, but i suppose it isn't necessary as 
> ASTWorker does that to make sure each LSP request gets a reply, and it can be 
> done with stale preambles.
> 
> Are there any other reasons for ASTWorker to empty the queue after stop?
Yeah, I think that's the only reason and the asymmetry is worthwhile here (esp 
because one preamble is way more expensive than one AST).

If that's not clear in the ASTworker piece, please do add a comment!



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:600
 Inputs, CompilerInvocationDiagConsumer, &CC1Args);
+auto OldPreamble = PW.getLatestBuiltPreamble();
+PW.requestBuild(Invocation.get(), Inputs);

kadircet wrote:
> sammccall wrote:
> > this doesn't seem correct (maybe ok in this patch because of the blocking, 
> > but not in general). You're assuming the last available preamble is the one 
> > that the last AST was built with.
> > 
> > I suppose you can't check the preamble of the current ParsedAST because it 
> > might not be cached, and you nevertheless want to skip rebuild if the 
> > diagnostics are going to be the same. I can't think of anything better than 
> > continuing to hold the shared_ptr for PreambleForLastBuiltAST or something 
> > like that.
> right, this is just a "hack" to keep this change NFC.
> 
> in the follow-up patches i am planning to signal whether latest built 
> preamble is reusable for a given `ParseInputs`, and also signal what the AST 
> should be patched with.
> 
> diagnostics(ast) will only be built if preamble is re-usable.
> right, this is just a "hack" to keep this change NFC.

can you add a comment about this? (In particular, why it's correct?)

> in the follow-up patches i am planning to signal whether latest built 
> preamble is reusable for a given ParseInputs

Does "reusable" mean "completely valid" (current semantics), or usable with 
some tweaks (e.g. added headers)? It would be good to define some precise 
terminology around this.

> diagnostics(ast) will only be built if preamble is re-usable.

SG



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:156
+/// Responsible for building and providing access to the preamble of a TU.
+/// Processes async build requests on a dedicated thread executing run method.
+/// Unless RunSync is provided, which will build preambles on the requesting

This sentence is hard to parse (processes, build, requests, and run are all 
ambiguous between nouns and verbs, and the pronouns, articles etc are missing).

Suggestion: "It processes updates asynchronously, building preambles on a 
dedicated thread. (This thread should be spawned externally and call the run() 
method)."



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:156
+/// Responsible for building and providing access to the preamble of a TU.
+/// Processes async build requests on a dedicated thread executing run method.
+/// Unless RunSync is provided, which will build preambles on the requesting

sammccall wrote:
> This sentence is hard to parse (processes, build, requests, and run are all 
> ambiguous between nouns and verbs, and the pronouns, articles etc are 
> missing).
> 
> Suggestion: "It processes updates asynchronously, building preambles on a 
> dedicated thread. (This thread should be spawned externally and call the 
> run() method)."
Actually, is "processing requests" really the clearest way to describe the 
model here?

What about "Whenever the thread is idle and the preamble is outdated, it starts 
to build a fresh preamble from the latest inputs."



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:157
+/// Processes async build requests on a dedicated thread executing run method.
+/// Unless RunSync is provided, which will build preambles on the requesting
+/// thread instead.

nit: "which" app

[PATCH] D76125: [clangd] Decouple preambleworker from astworker, NFCI

2020-03-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D76125#1926773 , @sammccall wrote:

> I think the only real outstanding thing is TUStatus, which we're still 
> discussing offline. Since this patch is intended to be NFC, I see two paths 
> consistent with the spirit of that


I'd really like to find any way to unblock this that isn't "redesign the API" 
because I don't think we should do that in a hurry. So also open to other ideas 
here, or happy to take a stab at this part if it's helpful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76125



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


[PATCH] D76291: [Support] Fix formatted_raw_ostream for UTF-8

2020-03-17 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard created this revision.
ostannard added reviewers: MaskRay, thakis, hoyFB, benlangmuir.
Herald added subscribers: cfe-commits, dexonsmith, hiraditya.
Herald added a project: clang.

- The getLine and getColumn functions need to update the position, or they will 
return stale data for buffered streams. This fixes a bug in the clang 
-analyzer-checker-option-help option, which was not wrapping the help text 
correctly when stdout is not a TTY.
- If the stream contains multi-byte UTF-8 sequences, then the whole sequence 
needs to be considered to be a single character. This has the edge case that 
the buffer might fill up and be flushed part way through a character.
- If the stream contains East Asian wide characters, these will be rendered 
twice as wide as other characters, so we need to increase the column count to 
match.

This doesn't attempt to handle everything unicode can do (combining characters, 
right-to-left markers, ...), but hopefully covers most things likely to be 
common in messages and source code we might want to print.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76291

Files:
  clang/test/Analysis/checker-plugins.c
  llvm/include/llvm/Support/FormattedStream.h
  llvm/lib/Support/FormattedStream.cpp
  llvm/unittests/Support/formatted_raw_ostream_test.cpp

Index: llvm/unittests/Support/formatted_raw_ostream_test.cpp
===
--- llvm/unittests/Support/formatted_raw_ostream_test.cpp
+++ llvm/unittests/Support/formatted_raw_ostream_test.cpp
@@ -29,4 +29,144 @@
   }
 }
 
+TEST(formatted_raw_ostreamTest, Test_LineColumn) {
+  // Test tracking of line and column numbers in a stream.
+  SmallString<128> A;
+  raw_svector_ostream B(A);
+  formatted_raw_ostream C(B);
+
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(0U, C.getColumn());
+
+  C << "a";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(1U, C.getColumn());
+
+  C << "bcdef";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(6U, C.getColumn());
+
+  // '\n' increments line number, sets column to zero.
+  C << "\n";
+  EXPECT_EQ(1U, C.getLine());
+  EXPECT_EQ(0U, C.getColumn());
+
+  // '\r sets coulmn to zero without changing line number
+  C << "foo\r";
+  EXPECT_EQ(1U, C.getLine());
+  EXPECT_EQ(0U, C.getColumn());
+
+  // '\t' advances column to the next multiple of 8.
+  // FIXME: If the column number is already a multiple of 8 this will do
+  // nothing, is this behaviour correct?
+  C << "1\t";
+  EXPECT_EQ(8U, C.getColumn());
+  C << "\t";
+  EXPECT_EQ(8U, C.getColumn());
+  C << "1234567\t";
+  EXPECT_EQ(16U, C.getColumn());
+  EXPECT_EQ(1U, C.getLine());
+}
+
+TEST(formatted_raw_ostreamTest, Test_Flush) {
+  // Flushing the buffer causes the charcters in the buffer to be scanned
+  // before the buffer is emptied, so line and column numbers will still be
+  // tracked properly.
+  SmallString<128> A;
+  raw_svector_ostream B(A);
+  B.SetBufferSize(32);
+  formatted_raw_ostream C(B);
+
+  C << "\nabc";
+  EXPECT_EQ(4U, C.GetNumBytesInBuffer());
+  C.flush();
+  EXPECT_EQ(1U, C.getLine());
+  EXPECT_EQ(3U, C.getColumn());
+  EXPECT_EQ(0U, C.GetNumBytesInBuffer());
+}
+
+TEST(formatted_raw_ostreamTest, Test_UTF8) {
+  SmallString<128> A;
+  raw_svector_ostream B(A);
+  B.SetBufferSize(32);
+  formatted_raw_ostream C(B);
+
+  // U+00A0 Non-breaking space: encoded as two bytes, but only one column wide.
+  C << "\u00a0";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(1U, C.getColumn());
+  EXPECT_EQ(2U, C.GetNumBytesInBuffer());
+
+  // U+2468 CIRCLED DIGIT NINE: encoded as three bytes, but only one column
+  // wide.
+  C << "\u2468";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(2U, C.getColumn());
+  EXPECT_EQ(5U, C.GetNumBytesInBuffer());
+
+  // U+0001 LINEAR B SYLLABLE B008 A: encoded as four bytes, but only one
+  // column wide.
+  C << "\U0001";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(3U, C.getColumn());
+  EXPECT_EQ(9U, C.GetNumBytesInBuffer());
+
+  // U+55B5, chinese character, encodes as three bytes, takes up two columns.
+  C << "\u55b5";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(5U, C.getColumn());
+  EXPECT_EQ(12U, C.GetNumBytesInBuffer());
+
+  // U+200B, zero-width space, encoded as three bytes but has no effect on the
+  // column or line number.
+  C << "\u200b";
+  EXPECT_EQ(0U, C.getLine());
+  EXPECT_EQ(5U, C.getColumn());
+  EXPECT_EQ(15U, C.GetNumBytesInBuffer());
+}
+
+TEST(formatted_raw_ostreamTest, Test_UTF8Buffered) {
+  SmallString<128> A;
+  raw_svector_ostream B(A);
+  B.SetBufferSize(4);
+  formatted_raw_ostream C(B);
+
+  // This character encodes as three bytes, so will cause the buffer to be
+  // flushed after the first byte (4 byte buffer, 3 bytes already written). We
+  // need to save the first part of the UTF-8 encoding until after the buffer is
+  // cleared and the remaining two bytes are written, at which point we can
+  // check the display width. In this case the display width is 1, so we end at
+  // colu

[clang-tools-extra] 704cd4d - [clangd] Only minimally escape text when rendering to markdown.

2020-03-17 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-17T17:10:20+01:00
New Revision: 704cd4d5d0754904361823588f203369c309deca

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

LOG: [clangd] Only minimally escape text when rendering to markdown.

Summary:
Conservatively escaping everything is bad in coc.nvim which shows the markdown
to the user, and we have reports of it causing problems for other parsers.

Fixes https://github.com/clangd/clangd/issues/301

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/FormattedString.cpp
clang-tools-extra/clangd/FormattedString.h
clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FormattedString.cpp 
b/clang-tools-extra/clangd/FormattedString.cpp
index 9cb732eabcf8..ecbc060a870a 100644
--- a/clang-tools-extra/clangd/FormattedString.cpp
+++ b/clang-tools-extra/clangd/FormattedString.cpp
@@ -12,6 +12,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
@@ -26,23 +27,143 @@ namespace clangd {
 namespace markup {
 
 namespace {
+
+// Is ' || Contents.startswith("/>"))
+  return true; // May close the tag.
+if (Contents.front() == '=')
+  return true; // Don't try to parse attribute values.
+return false;  // Random punctuation means this isn't a tag.
+  }
+  return true; // Potentially incomplete tag.
+}
+
+// Tests whether C should be backslash-escaped in markdown.
+// The string being escaped is Before + C + After. This is part of a paragraph.
+// StartsLine indicates whether `Before` is the start of the line.
+// After may not be everything until the end of the line.
+//
+// It's always safe to escape punctuation, but want minimal escaping.
+// The strategy is to escape the first character of anything that might start
+// a markdown grammar construct.
+bool needsLeadingEscape(char C, llvm::StringRef Before, llvm::StringRef After,
+bool StartsLine) {
+  assert(Before.take_while(isWhitespace).empty());
+  auto RulerLength = [&]() -> /*Length*/ unsigned {
+if (!StartsLine || !Before.empty())
+  return false;
+llvm::StringRef A = After.rtrim();
+return llvm::all_of(A, [C](char D) { return C == D; }) ? 1 + A.size() : 0;
+  };
+  auto IsBullet = [&]() {
+return StartsLine && Before.empty() &&
+   (After.empty() || After.startswith(" "));
+  };
+  auto SpaceSurrounds = [&]() {
+return (After.empty() || isWhitespace(After.front())) &&
+   (Before.empty() || isWhitespace(Before.back()));
+  };
+  auto WordSurrounds = [&]() {
+return (!After.empty() && llvm::isAlnum(After.front())) &&
+   (!Before.empty() && llvm::isAlnum(Before.back()));
+  };
+
+  switch (C) {
+  case '\\': // Escaped character.
+return true;
+  case '`': // Code block or inline code
+// Any number of backticks can delimit an inline code block that can end
+// anywhere (including on another line). We must escape them all.
+return true;
+  case '~': // Code block
+return StartsLine && Before.empty() && After.startswith("~~");
+  case '#': { // ATX heading.
+if (!StartsLine || !Before.empty())
+  return false;
+llvm::StringRef Rest = After.ltrim(C);
+return Rest.empty() || Rest.startswith(" ");
+  }
+  case ']': // Link or link reference.
+// We escape ] rather than [ here, because it's more constrained:
+//   ](...) is an in-line link
+//   ]: is a link reference
+// The following are only links if the link reference exists:
+//   ] by itself is a shortcut link
+//   ][...] is an out-of-line link
+// Because we never emit link references, we don't need to handle these.
+return After.startswith(":") || After.startswith("(");
+  case '=': // Setex heading.
+return RulerLength() > 0;
+  case '_': // Horizontal ruler or matched delimiter.
+if (RulerLength() >= 3)
+  return true;
+// Not a delimiter if surrounded by space, or inside a word.
+// (The rules at word boundaries are subtle).
+return !(SpaceSurrounds() || WordSurrounds());
+  case '-': // Setex heading, horizontal ruler, or bullet.
+if (RulerLength() > 0)
+  return true;
+return IsBullet();
+  case '+': // Bullet list.
+return IsBullet();
+  case '*': // Bullet list, horizontal ruler, or delimiter.
+return IsBullet() || RulerLength() >= 3 || !SpaceSur

[clang] 08ab8c9 - [NFC] Add UsedDeclVisitor

2020-03-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-03-17T12:12:40-04:00
New Revision: 08ab8c9af4dd27cb306b449edc9a9c50ed11194a

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

LOG: [NFC] Add UsedDeclVisitor

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

Added: 
clang/lib/Sema/UsedDeclVisitor.h

Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c1bfb962677a..e6afe7a5b421 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "TreeTransform.h"
+#include "UsedDeclVisitor.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
@@ -17400,71 +17401,33 @@ void 
Sema::MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T) {
 }
 
 namespace {
-  /// Helper class that marks all of the declarations referenced by
-  /// potentially-evaluated subexpressions as "referenced".
-  class EvaluatedExprMarker : public EvaluatedExprVisitor 
{
-Sema &S;
-bool SkipLocalVariables;
-
-  public:
-typedef EvaluatedExprVisitor Inherited;
-
-EvaluatedExprMarker(Sema &S, bool SkipLocalVariables)
-  : Inherited(S.Context), S(S), SkipLocalVariables(SkipLocalVariables) { }
-
-void VisitDeclRefExpr(DeclRefExpr *E) {
-  // If we were asked not to visit local variables, don't.
-  if (SkipLocalVariables) {
-if (VarDecl *VD = dyn_cast(E->getDecl()))
-  if (VD->hasLocalStorage())
-return;
-  }
-
-  S.MarkDeclRefReferenced(E);
-}
-
-void VisitMemberExpr(MemberExpr *E) {
-  S.MarkMemberReferenced(E);
-  Inherited::VisitMemberExpr(E);
-}
-
-void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
-  S.MarkFunctionReferenced(
-  E->getBeginLoc(),
-  const_cast(E->getTemporary()->getDestructor()));
-  Visit(E->getSubExpr());
-}
+/// Helper class that marks all of the declarations referenced by
+/// potentially-evaluated subexpressions as "referenced".
+class EvaluatedExprMarker : public UsedDeclVisitor {
+public:
+  typedef UsedDeclVisitor Inherited;
+  bool SkipLocalVariables;
 
-void VisitCXXNewExpr(CXXNewExpr *E) {
-  if (E->getOperatorNew())
-S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorNew());
-  if (E->getOperatorDelete())
-S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete());
-  Inherited::VisitCXXNewExpr(E);
-}
+  EvaluatedExprMarker(Sema &S, bool SkipLocalVariables)
+  : Inherited(S), SkipLocalVariables(SkipLocalVariables) {}
 
-void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
-  if (E->getOperatorDelete())
-S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete());
-  QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType());
-  if (const RecordType *DestroyedRec = Destroyed->getAs()) {
-CXXRecordDecl *Record = cast(DestroyedRec->getDecl());
-S.MarkFunctionReferenced(E->getBeginLoc(), S.LookupDestructor(Record));
-  }
-
-  Inherited::VisitCXXDeleteExpr(E);
-}
+  void visitUsedDecl(SourceLocation Loc, Decl *D) {
+S.MarkFunctionReferenced(Loc, cast(D));
+  }
 
-void VisitCXXConstructExpr(CXXConstructExpr *E) {
-  S.MarkFunctionReferenced(E->getBeginLoc(), E->getConstructor());
-  Inherited::VisitCXXConstructExpr(E);
+  void VisitDeclRefExpr(DeclRefExpr *E) {
+// If we were asked not to visit local variables, don't.
+if (SkipLocalVariables) {
+  if (VarDecl *VD = dyn_cast(E->getDecl()))
+if (VD->hasLocalStorage())
+  return;
 }
+S.MarkDeclRefReferenced(E);
+  }
 
-void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
-  Visit(E->getExpr());
-}
-  };
-}
+  void VisitMemberExpr(MemberExpr *E) { S.MarkMemberReferenced(E); }
+};
+} // namespace
 
 /// Mark any declarations that appear within this expression or any
 /// potentially-evaluated subexpressions as "referenced".

diff  --git a/clang/lib/Sema/UsedDeclVisitor.h 
b/clang/lib/Sema/UsedDeclVisitor.h
new file mode 100644
index ..be46f0d4affc
--- /dev/null
+++ b/clang/lib/Sema/UsedDeclVisitor.h
@@ -0,0 +1,90 @@
+//===- UsedDeclVisitor.h - ODR-used declarations visitor *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//===--===//
+//
+//  This file defines UsedDeclVisitor, a CRTP class which visits all the
+//  declarations 

[PATCH] D76289: [NFC][Attr TableGen] Emit Spelling Enum for Attr types if there >1

2020-03-17 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:2333
-if (!ElideSpelling)
-  SpellingEnum = CreateSemanticSpellings(Spellings, 
SemanticToSyntacticMap);
-if (Header)

I had to call this function during both header and cpp file generation because 
some code later used the `SemanticToSyntacticMap` it fills in.



Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:2534
 if (!ElideSpelling) {
   assert(!SemanticToSyntacticMap.empty() && "Empty semantic mapping list");
   if (Header)

Won't this assert? I think we come here even if !Header.


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

https://reviews.llvm.org/D76289



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


[PATCH] D76289: [NFC][Attr TableGen] Emit Spelling Enum for Attr types if there >1

2020-03-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I cannot think of a way to add test coverage for this change, can you?




Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:2332
+if (Header && Spellings.size() > 1)
+  OS <<  CreateSemanticSpellings(Spellings, SemanticToSyntacticMap);
 

Looks like there is a little extra whitespace after the `<<` that can be 
removed.


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

https://reviews.llvm.org/D76289



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


[PATCH] D76229: [clang-tidy] Added PlacementNewStorageCheck

2020-03-17 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D76229#1925363 , @f00kat wrote:

> In D76229#1925268 , @aaron.ballman 
> wrote:
>
> > Have you considered making this a static analyzer check as opposed to a 
> > clang-tidy check? I think using dataflow analysis will really reduce the 
> > false positives because it will be able to track the allocation and 
> > alignment data across control flow.
>
>
> I have never try to write static analyzer before. Okay, I will look at 
> examples of how to work with dataflow.


To getting started with the Analyzer please visit @NoQ's (tiny bit outdated) 
booklet: https://github.com/haoNoQ/clang-analyzer-guide

Advertisement:
If D69726  lands we will have an arsenal of 
APIs for helping dynamic size based checkers.
If D73521  lands it should be easier to 
getting started with the Analyzer, but now you could visit what is our current 
API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76229



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


[PATCH] D75687: [clangd] Only minimally escape text when rendering to markdown.

2020-03-17 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG704cd4d5d075: [clangd] Only minimally escape text when 
rendering to markdown. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75687

Files:
  clang-tools-extra/clangd/FormattedString.cpp
  clang-tools-extra/clangd/FormattedString.h
  clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1905,7 +1905,7 @@
   llvm::StringRef ExpectedMarkdown = R"md(### variable `foo`  
 
 ---
-Value \= `val`  
+Value = `val`  
 
 ---
 ```cpp
Index: clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
===
--- clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
+++ clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
@@ -17,25 +17,96 @@
 namespace markup {
 namespace {
 
-TEST(Render, Escaping) {
-  // Check some ASCII punctuation
-  Paragraph P;
-  P.appendText("*!`");
-  EXPECT_EQ(P.asMarkdown(), "\\*\\!\\`");
+std::string escape(llvm::StringRef Text) {
+  return Paragraph().appendText(Text.str()).asMarkdown();
+}
+
+MATCHER_P(escaped, C, "") {
+  return testing::ExplainMatchResult(::testing::HasSubstr(std::string{'\\', C}),
+ arg, result_listener);
+}
 
+MATCHER(escapedNone, "") {
+  return testing::ExplainMatchResult(::testing::Not(::testing::HasSubstr("\\")),
+ arg, result_listener);
+}
+
+TEST(Render, Escaping) {
   // Check all ASCII punctuation.
-  P = Paragraph();
   std::string Punctuation = R"txt(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)txt";
-  // Same text, with each character escaped.
-  std::string EscapedPunctuation;
-  EscapedPunctuation.reserve(2 * Punctuation.size());
-  for (char C : Punctuation)
-EscapedPunctuation += std::string("\\") + C;
-  P.appendText(Punctuation);
-  EXPECT_EQ(P.asMarkdown(), EscapedPunctuation);
+  std::string EscapedPunc = R"txt(!"#$%&'()\*+,-./:;<=>?@[\\]^\_\`{|}~)txt";
+  EXPECT_EQ(escape(Punctuation), EscapedPunc);
+
+  // Inline code
+  EXPECT_EQ(escape("`foo`"), R"(\`foo\`)");
+  EXPECT_EQ(escape("`foo"), R"(\`foo)");
+  EXPECT_EQ(escape("foo`"), R"(foo\`)");
+  EXPECT_EQ(escape("``foo``"), R"(\`\`foo\`\`)");
+  // Code blocks
+  EXPECT_EQ(escape("```"), R"(\`\`\`)"); // This could also be inline code!
+  EXPECT_EQ(escape("~~~"), R"(\~~~)");
+
+  // Rulers and headings
+  EXPECT_THAT(escape("## Heading"), escaped('#'));
+  EXPECT_THAT(escape("Foo # bar"), escapedNone());
+  EXPECT_EQ(escape("---"), R"(\---)");
+  EXPECT_EQ(escape("-"), R"(\-)");
+  EXPECT_EQ(escape("==="), R"(\===)");
+  EXPECT_EQ(escape("="), R"(\=)");
+  EXPECT_EQ(escape("***"), R"(\*\*\*)"); // \** could start emphasis!
+
+  // HTML tags.
+  EXPECT_THAT(escape(""), escaped('<'));
+  EXPECT_THAT(escape("std::vector"), escaped('<'));
+  EXPECT_THAT(escape("std::map"), escapedNone());
+  // Autolinks
+  EXPECT_THAT(escape("Email "), escapedNone());
+  EXPECT_THAT(escape("Website "), escapedNone());
+
+  // Bullet lists.
+  EXPECT_THAT(escape("- foo"), escaped('-'));
+  EXPECT_THAT(escape("* foo"), escaped('*'));
+  EXPECT_THAT(escape("+ foo"), escaped('+'));
+  EXPECT_THAT(escape("+"), escaped('+'));
+  EXPECT_THAT(escape("a + foo"), escapedNone());
+  EXPECT_THAT(escape("a+ foo"), escapedNone());
+  EXPECT_THAT(escape("1. foo"), escaped('.'));
+  EXPECT_THAT(escape("a. foo"), escapedNone());
+
+  // Emphasis.
+  EXPECT_EQ(escape("*foo*"), R"(\*foo\*)");
+  EXPECT_EQ(escape("**foo**"), R"(\*\*foo\*\*)");
+  EXPECT_THAT(escape("*foo"), escaped('*'));
+  EXPECT_THAT(escape("foo *"), escapedNone());
+  EXPECT_THAT(escape("foo * bar"), escapedNone());
+  EXPECT_THAT(escape("foo_bar"), escapedNone());
+  EXPECT_THAT(escape("foo _bar"), escaped('_'));
+  EXPECT_THAT(escape("foo_ bar"), escaped('_'));
+  EXPECT_THAT(escape("foo _ bar"), escapedNone());
+
+  // HTML entities.
+  EXPECT_THAT(escape("fish &chips;"), escaped('&'));
+  EXPECT_THAT(escape("fish & chips;"), escapedNone());
+  EXPECT_THAT(escape("fish &chips"), escapedNone());
+  EXPECT_THAT(escape("foo * bar"), escaped('&'));
+  EXPECT_THAT(escape("foo ¯ bar"), escaped('&'));
+  EXPECT_THAT(escape("foo &?; bar"), escapedNone());
+
+  // Links.
+  EXPECT_THAT(escape("[foo](bar)"), escaped(']'));
+  EXPECT_THAT(escape("[foo]: bar"), escaped(']'));
+  // No need to escape these, as the target never exists.
+  EXPECT_THAT(escape("[foo][]"), escapedNone());
+  EXPECT_THAT(escape("[foo][bar]"), escapedNone());
+  EXPECT_THAT(escape("[foo]"), escapedNone());
 
   // In code blocks we don't need to escape ASC

[PATCH] D76262: [NFC] Add UsedDeclVisitor

2020-03-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG08ab8c9af4dd: [NFC] Add UsedDeclVisitor (authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76262

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/UsedDeclVisitor.h

Index: clang/lib/Sema/UsedDeclVisitor.h
===
--- /dev/null
+++ clang/lib/Sema/UsedDeclVisitor.h
@@ -0,0 +1,90 @@
+//===- UsedDeclVisitor.h - ODR-used declarations visitor *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//===--===//
+//
+//  This file defines UsedDeclVisitor, a CRTP class which visits all the
+//  declarations that are ODR-used by an expression or statement.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
+#define LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
+
+#include "clang/AST/EvaluatedExprVisitor.h"
+#include "clang/Sema/SemaInternal.h"
+
+namespace clang {
+template 
+class UsedDeclVisitor : public EvaluatedExprVisitor {
+protected:
+  Sema &S;
+
+public:
+  typedef EvaluatedExprVisitor Inherited;
+
+  UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
+
+  Derived &asImpl() { return *static_cast(this); }
+
+  void VisitDeclRefExpr(DeclRefExpr *E) {
+auto *D = E->getDecl();
+if (isa(D) || isa(D)) {
+  asImpl().visitUsedDecl(E->getLocation(), D);
+}
+  }
+
+  void VisitMemberExpr(MemberExpr *E) {
+auto *D = E->getMemberDecl();
+if (isa(D) || isa(D)) {
+  asImpl().visitUsedDecl(E->getMemberLoc(), D);
+}
+asImpl().Visit(E->getBase());
+  }
+
+  void VisitCapturedStmt(CapturedStmt *Node) {
+asImpl().visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
+Inherited::VisitCapturedStmt(Node);
+  }
+
+  void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+asImpl().visitUsedDecl(
+E->getBeginLoc(),
+const_cast(E->getTemporary()->getDestructor()));
+asImpl().Visit(E->getSubExpr());
+  }
+
+  void VisitCXXNewExpr(CXXNewExpr *E) {
+if (E->getOperatorNew())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
+if (E->getOperatorDelete())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
+Inherited::VisitCXXNewExpr(E);
+  }
+
+  void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+if (E->getOperatorDelete())
+  asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
+QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType());
+if (const RecordType *DestroyedRec = Destroyed->getAs()) {
+  CXXRecordDecl *Record = cast(DestroyedRec->getDecl());
+  asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
+}
+
+Inherited::VisitCXXDeleteExpr(E);
+  }
+
+  void VisitCXXConstructExpr(CXXConstructExpr *E) {
+asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
+Inherited::VisitCXXConstructExpr(E);
+  }
+
+  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
+asImpl().Visit(E->getExpr());
+  }
+};
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "TreeTransform.h"
+#include "UsedDeclVisitor.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
@@ -17400,71 +17401,33 @@
 }
 
 namespace {
-  /// Helper class that marks all of the declarations referenced by
-  /// potentially-evaluated subexpressions as "referenced".
-  class EvaluatedExprMarker : public EvaluatedExprVisitor {
-Sema &S;
-bool SkipLocalVariables;
-
-  public:
-typedef EvaluatedExprVisitor Inherited;
-
-EvaluatedExprMarker(Sema &S, bool SkipLocalVariables)
-  : Inherited(S.Context), S(S), SkipLocalVariables(SkipLocalVariables) { }
-
-void VisitDeclRefExpr(DeclRefExpr *E) {
-  // If we were asked not to visit local variables, don't.
-  if (SkipLocalVariables) {
-if (VarDecl *VD = dyn_cast(E->getDecl()))
-  if (VD->hasLocalStorage())
-return;
-  }
-
-  S.MarkDeclRefReferenced(E);
-}
-
-void VisitMemberExpr(MemberExpr *E) {
-  S.MarkMemberReferenced(E);
-  Inherited::VisitMemberExpr(E);
-}
-
-void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
-  S.MarkFunctionReferenced(
-  E->getBeginLoc(),

[PATCH] D76295: Use 64 bit integers for bit offsets inside AST file

2020-03-17 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added a project: clang.
Herald added subscribers: usaxena95, kadircet, ilya-biryukov.

This diff is for discussion how to address problem with large preamble file.

32 bit offsets can be used for PCH/preamble files below 512M. This diff fixes
crashes and asserts on clangd when preamble file exceeds 512M limit. The asserts
usually look like "LLVM ERROR: Invalid abbrev number". On about 700M preamble
files this patch increases file size on about 4%. I tested this diff on
Clang 8, 9 and master.

Test Plan:
Tested on clangd with 700M preamble file. 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76295

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1889,7 +1889,7 @@
 
   // Write out the source location entry table. We skip the first
   // entry, which is always the same dummy entry.
-  std::vector SLocEntryOffsets;
+  std::vector SLocEntryOffsets;
   RecordData PreloadSLocs;
   SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1);
   for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size();
@@ -2212,7 +2212,7 @@
   /// For each identifier that is associated with a macro, this map
   /// provides the offset into the bitstream where that macro is
   /// defined.
-  std::vector MacroOffsets;
+  std::vector MacroOffsets;
 
   for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) {
 const IdentifierInfo *Name = MacroInfosToEmit[I].Name;
@@ -3269,7 +3269,7 @@
   DataLen += 2; // 2 bytes for builtin ID
   DataLen += 2; // 2 bytes for flags
   if (MacroOffset)
-DataLen += 4; // MacroDirectives offset.
+DataLen += 8; // MacroDirectives offset.
 
   if (NeedDecls) {
 for (IdentifierResolver::iterator D = IdResolver.begin(II),
@@ -,7 +,7 @@
 LE.write(Bits);
 
 if (HadMacroDefinition)
-  LE.write(MacroOffset);
+  LE.write(MacroOffset);
 
 if (NeedDecls) {
   // Emit the declaration IDs in reverse order, because the
@@ -4241,7 +4241,7 @@
 
 /// Note that the identifier II occurs at the given offset
 /// within the identifier table.
-void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) {
+void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint64_t Offset) {
   IdentID ID = IdentifierIDs[II];
   // Only store offsets new to this AST file. Other identifier names are looked
   // up earlier in the chain and thus don't need an offset.
@@ -4251,7 +4251,7 @@
 
 /// Note that the selector Sel occurs at the given offset
 /// within the method pool/selector table.
-void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) {
+void ASTWriter::SetSelectorOffset(Selector Sel, uint64_t Offset) {
   unsigned ID = SelectorIDs[Sel];
   assert(ID && "Unknown selector");
   // Don't record offsets for selectors that are also available in a different
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1000,9 +1000,9 @@
   // If this identifier is a macro, deserialize the macro
   // definition.
   if (HadMacroDefinition) {
-uint32_t MacroDirectivesOffset =
-endian::readNext(d);
-DataLen -= 4;
+uint64_t MacroDirectivesOffset =
+endian::readNext(d);
+DataLen -= 8;
 
 Reader.addPendingMacro(II, &F, MacroDirectivesOffset);
   }
@@ -3187,7 +3187,7 @@
 Error("duplicate IDENTIFIER_OFFSET record in AST file");
 return Failure;
   }
-  F.IdentifierOffsets = (const uint32_t *)Blob.data();
+  F.IdentifierOffsets = (const uint64_t *)Blob.data();
   F.LocalNumIdentifiers = Record[0];
   unsigned LocalBaseIdentifierID = Record[1];
   F.BaseIdentifierID = getTotalNumIdentifiers();
@@ -3290,7 +3290,7 @@
   break;
 
 case SELECTOR_OFFSETS: {
-  F.SelectorOffsets = (const uint32_t *)Blob.data();
+  F.SelectorOffsets = (const uint64_t *)Blob.data();
   F.LocalNumSelectors = Record[0];
   unsigned LocalBaseSelectorID = Record[1];
   F.BaseSelectorID = getTotalNumSelectors();
@@ -3371,7 +3371,7 @@
   break;
 
 case SOURCE_LOCATION_OFFSETS: {
-  F.SLocEntryOffsets = (const uint32_t *)Blob.data();
+  F.SLocEntryOffsets = (const uint64_t *)Blob.data();
   F.LocalNumSLocEntries = Record[0];
   unsigned SLocSpaceSize = Record[1];
   std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) =
@@ -3689,7 +3689,7 @@
 Error("duplicate MACRO_OFFSET record in AST file");
 return Failure;
   }
-  F.MacroOffsets = (const uint32_t *)Blob.dat

[PATCH] D75175: [CallSiteInfo] Enable the call site info only for -g + optimizations

2020-03-17 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Sorry for the delay here.




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:793
 Opts.EnableDebugEntryValues = Args.hasArg(OPT_femit_debug_entry_values);
+Opts.EmitCallSiteInfo = true;
+  }

djtodoro wrote:
> vsk wrote:
> > I don't understand how Opts.EnableDebugEntryValues and 
> > Opts.EmitCallSiteInfo are different. What is the second option supposed to 
> > control, that the first option does not? I thought we could already 
> > suppress entry values in llvm at -O0 + -g.
> > 
> > Is `EmitCallSiteInfo = false` supposed to disable TAG_call_site emission?
> I'll try to describe the difference between Call Site Info and entry values.
> 
> Entry values (call-site-params and dbg-values with dw_op_entry_val) are 
> features from debug info. The call-site-params are extension of the call-site 
> (`TAG_call_site`) debug info. Since the emission of the `TAG_call_site` was 
> already restricted to `-O>0 + -g` in the `constructCallSiteEntryDIEs()` 
> (there is a code checking the existence of the `AllCallsDescribed`), that 
> implies the `collectCallSiteParameters()` will be called for that combination 
> only (since it is being called in the `constructCallSiteEntryDIEs()`). 
> Further on, the `collectCallSiteParameters()` will call the 
> `describeLoadedValue()`, which is target-dependent method, and it is 
> implemented only for x86, arm and aarch64 targets at the moment, so we need 
> to restrict the emission of call-site-params only to the targets.
> 
> The Call Site Info is utility helping us implementing the entry values. We 
> did not have the information about arguments forwarding (necessary for 
> implementing the `describeLoadedValue()` by searching for the values loaded 
> into the forwarding registers), so the conclusion was to add such info as 
> `MF` attribute (callSites:). In addition, there were thoughts the attribute 
> could be used by other places in LLVM, but currently it is being used only by 
> Debug Entry Values feature. My understanding is the `MF` attribute is 
> different thing to the Debug Entry Values, and we can not restrict the 
> production of such attribute by looking at the Debug Info Metadata (for 
> example by looking at the `AllCallsDescribed` flag), so that is why I added 
> the additional flag.
> 
> 
> > Is EmitCallSiteInfo = false supposed to disable TAG_call_site emission?
> No, it should restrict only the `callSites` `MF` attribute.
> 
Thanks for explaining, this sgtm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75175



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


[PATCH] D75682: [Analyzer][StreamChecker] Introduction of stream error handling.

2020-03-17 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

In D75682#1926732 , @Szelethus wrote:

> Rght I think I finally get it. You don't want to state split on `feof()` 
> and `ferror()`, but rather on the stream operations!


Yes the split is at the operations. I did not think even of splitting at start 
of `feof` to determine "backwards" the result of the previous operation. This 
could be another approach. But the way of split depends on the previous 
operation (to check if error is possible based on possible constraints on its 
return value), probably not better (but less state split?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75682



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


[PATCH] D76296: [ARM,CDE] Implement GPR CDE intrinsics

2020-03-17 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: simon_tatham, MarkMurrayARM, dmgreen, ostannard.
Herald added subscribers: cfe-commits, danielkiss, hiraditya, kristof.beyls.
Herald added a project: clang.
miyuki added a parent revision: D76298: [ARM,CDE] Implement CDE S and 
D-register intrinsics.
miyuki removed a parent revision: D76298: [ARM,CDE] Implement CDE S and 
D-register intrinsics.
miyuki added a child revision: D76298: [ARM,CDE] Implement CDE S and D-register 
intrinsics.

This change implements ACLE CDE intrinsics that translate to
instructions working with general-purpose registers.

The specification is available at
https://static.docs.arm.com/101028/0010/ACLE_2019Q4_release-0010.pdf

Each ACLE intrinsic gets a corresponding LLVM IR intrinsic (because
they have distinct function prototypes). Dual-register operands are
represented as pairs of i32 values. Because of this the instruction
selection for these intrinsics cannot be represented as TableGen
patterns and requires custom C++ code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76296

Files:
  clang/include/clang/Basic/arm_cde.td
  clang/test/CodeGen/arm-cde-gpr.c
  clang/test/Sema/arm-cde-immediates.c
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
  llvm/lib/Target/ARM/ARMInstrCDE.td
  llvm/test/CodeGen/Thumb2/cde-gpr.ll

Index: llvm/test/CodeGen/Thumb2/cde-gpr.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/cde-gpr.ll
@@ -0,0 +1,189 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+cdecp0 -mattr=+cdecp1 -verify-machineinstrs -o - %s | FileCheck %s
+; RUN: llc -mtriple=thumbebv8.1m.main -mattr=+cdecp0 -mattr=+cdecp1 -verify-machineinstrs -o - %s | FileCheck %s
+
+declare i32 @llvm.arm.cde.cx1(i32 immarg, i32 immarg)
+declare i32 @llvm.arm.cde.cx1a(i32 immarg, i32, i32 immarg)
+declare { i32, i32 } @llvm.arm.cde.cx1d(i32 immarg, i32 immarg)
+declare { i32, i32 } @llvm.arm.cde.cx1da(i32 immarg, i32, i32, i32 immarg)
+
+declare i32 @llvm.arm.cde.cx2(i32 immarg, i32, i32 immarg)
+declare i32 @llvm.arm.cde.cx2a(i32 immarg, i32, i32, i32 immarg)
+declare { i32, i32 } @llvm.arm.cde.cx2d(i32 immarg, i32, i32 immarg)
+declare { i32, i32 } @llvm.arm.cde.cx2da(i32 immarg, i32, i32, i32, i32 immarg)
+
+declare i32 @llvm.arm.cde.cx3(i32 immarg, i32, i32, i32 immarg)
+declare i32 @llvm.arm.cde.cx3a(i32 immarg, i32, i32, i32, i32 immarg)
+declare { i32, i32 } @llvm.arm.cde.cx3d(i32 immarg, i32, i32, i32 immarg)
+declare { i32, i32 } @llvm.arm.cde.cx3da(i32 immarg, i32, i32, i32, i32, i32 immarg)
+
+define arm_aapcs_vfpcc i32 @test_cx1() {
+; CHECK-LABEL: test_cx1:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:cx1 p0, r0, #123
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call i32 @llvm.arm.cde.cx1(i32 0, i32 123)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i32 @test_cx1a(i32 %acc) {
+; CHECK-LABEL: test_cx1a:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:cx1a p0, r0, #345
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call i32 @llvm.arm.cde.cx1a(i32 0, i32 %acc, i32 345)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i64 @test_cx1d() {
+; CHECK-LABEL: test_cx1d:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:cx1d p1, r0, r1, #567
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call { i32, i32 } @llvm.arm.cde.cx1d(i32 1, i32 567)
+  %1 = extractvalue { i32, i32 } %0, 1
+  %2 = zext i32 %1 to i64
+  %3 = shl i64 %2, 32
+  %4 = extractvalue { i32, i32 } %0, 0
+  %5 = zext i32 %4 to i64
+  %6 = or i64 %3, %5
+  ret i64 %6
+}
+
+define arm_aapcs_vfpcc i64 @test_cx1da(i64 %acc) {
+; CHECK-LABEL: test_cx1da:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:@ kill: def $r1 killed $r1 killed $r0_r1 def $r0_r1
+; CHECK-NEXT:@ kill: def $r0 killed $r0 killed $r0_r1 def $r0_r1
+; CHECK-NEXT:cx1da p0, r0, r1, #789
+; CHECK-NEXT:bx lr
+entry:
+  %0 = lshr i64 %acc, 32
+  %1 = trunc i64 %0 to i32
+  %2 = trunc i64 %acc to i32
+  %3 = call { i32, i32 } @llvm.arm.cde.cx1da(i32 0, i32 %2, i32 %1, i32 789)
+  %4 = extractvalue { i32, i32 } %3, 1
+  %5 = zext i32 %4 to i64
+  %6 = shl i64 %5, 32
+  %7 = extractvalue { i32, i32 } %3, 0
+  %8 = zext i32 %7 to i64
+  %9 = or i64 %6, %8
+  ret i64 %9
+}
+
+define arm_aapcs_vfpcc i32 @test_cx2(i32 %n) {
+; CHECK-LABEL: test_cx2:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:cx2 p0, r0, r0, #11
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call i32 @llvm.arm.cde.cx2(i32 0, i32 %n, i32 11)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i32 @test_cx2a(i32 %acc, i32 %n) {
+; CHECK-LABEL: test_cx2a:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:cx2a p1, r0, r1, #22
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call i32 @llvm.arm.cde.cx2a(i32 1, i32 %acc, i32 %n, i32 22)
+  ret i32 %0
+}
+
+define arm_aapcs_vfpcc i64 @test_cx2d(i32 %n) #0 {
+; CHECK-LABEL: test_cx2d:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:cx2d p1, r0

[PATCH] D76297: [clang][AArch64] readd support for 'p' inline asm constraint

2020-03-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added a reviewer: eli.friedman.
Herald added subscribers: cfe-commits, kristof.beyls.
Herald added a project: clang.
nickdesaulniers marked an inline comment as done.
sdesmalen accepted this revision.
sdesmalen added a comment.
This revision is now accepted and ready to land.
nickdesaulniers updated this revision to Diff 250812.
nickdesaulniers marked an inline comment as done.

LGTM!


nickdesaulniers added a comment.

- fix 'U' case




Comment at: clang/lib/Basic/Targets/AArch64.h:97
   Constraint += 2;
   break;
 }

nit: does this need a `default: break`?



Comment at: clang/lib/Basic/Targets/AArch64.h:98
   break;
-default:
-  R = std::string(1, *Constraint);
-  break;
 }
+return TargetInfo::convertConstraint(Constraint);

bah, need to return `R` for the previous case.


Was accidentally removed by commit af64948e2a05 
 when it 
overrode
TargetInfo::convertConstraint.

Fixes: pr/45225


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76297

Files:
  clang/lib/Basic/Targets/AArch64.h
  clang/test/CodeGen/inline-asm-p-constraint.c


Index: clang/test/CodeGen/inline-asm-p-constraint.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-asm-p-constraint.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple aarch64-linux-gnu | FileCheck %s
+void foo(void* ptr) {
+  asm volatile("prfm pldl1keep, %a0\n" : : "p" (ptr));
+  // CHECK: call void asm sideeffect "prfm pldl1keep, ${0:a}\0A", "r"(i8* 
%0)
+  // CHECK-NOT: call void asm sideeffect "prfm pldl1keep, ${0:a}\0A", "p"(i8* 
%0)
+}
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -96,7 +96,7 @@
   Constraint += 2;
   break;
 default:
-  R = std::string(1, *Constraint);
+  R = TargetInfo::convertConstraint(Constraint);
   break;
 }
 return R;


Index: clang/test/CodeGen/inline-asm-p-constraint.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-asm-p-constraint.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple aarch64-linux-gnu | FileCheck %s
+void foo(void* ptr) {
+  asm volatile("prfm pldl1keep, %a0\n" : : "p" (ptr));
+  // CHECK: call void asm sideeffect "prfm pldl1keep, ${0:a}\0A", "r"(i8* %0)
+  // CHECK-NOT: call void asm sideeffect "prfm pldl1keep, ${0:a}\0A", "p"(i8* %0)
+}
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -96,7 +96,7 @@
   Constraint += 2;
   break;
 default:
-  R = std::string(1, *Constraint);
+  R = TargetInfo::convertConstraint(Constraint);
   break;
 }
 return R;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

2020-03-17 Thread Alexey Sachkov via Phabricator via cfe-commits
AlexeySachkov added inline comments.



Comment at: clang/include/clang/AST/Type.h:1827-1830
+if (Dependent)
+  Deps |= TypeDependence::Dependent | TypeDependence::Instantiation;
+if (InstantiationDependent)
+  Deps |= TypeDependence::Instantiation;

@ilya-biryukov, Is this code snippet correct?

It seems to be, that it should look like:
```
if (Dependent)
  Deps |= TypeDependence::Dependent;
if (InstantiationDependent)
  Deps |= TypeDependence::Dependent | TypeDependence::Instantiation;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920



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


[PATCH] D76297: [clang][AArch64] readd support for 'p' inline asm constraint

2020-03-17 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen accepted this revision.
sdesmalen added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/lib/Basic/Targets/AArch64.h:97
   Constraint += 2;
   break;
 }

nit: does this need a `default: break`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76297



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


[PATCH] D76283: [IRBuilder] Use preferred target type for len argument of memory intrinsic functions

2020-03-17 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

llvm-dev might be a better place for that question, wider coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76283



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


[PATCH] D75682: [Analyzer][StreamChecker] Introduction of stream error handling.

2020-03-17 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.
Herald added a subscriber: DenisDvlp.

In D75682#1926732 , @Szelethus wrote:

> How about untracked streams? What if we call `feof()` on a stream we got from 
> a parameter, wouldn't that suggest that the stream is probably non-null and 
> could either be EOF or non-EOF?


Currently the operation is completely ignored on untracked stream. Could start 
with a non-null stream and every error case is possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75682



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


[PATCH] D76298: [ARM,CDE] Implement CDE S and D-register intrinsics

2020-03-17 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: simon_tatham, MarkMurrayARM, ostannard, dmgreen.
Herald added subscribers: cfe-commits, danielkiss, hiraditya, kristof.beyls.
Herald added a project: clang.
miyuki added a child revision: D76296: [ARM,CDE] Implement GPR CDE intrinsics.
miyuki removed a child revision: D76296: [ARM,CDE] Implement GPR CDE intrinsics.
miyuki added a parent revision: D76296: [ARM,CDE] Implement GPR CDE intrinsics.
miyuki added a child revision: D76299: [ARM,CDE] Implement CDE unpredicated 
Q-register intrinsics.

This patch implements the following ACLE intrinsics:

  uint32_t __arm_vcx1_u32(int coproc, uint32_t imm);
  uint32_t __arm_vcx1a_u32(int coproc, uint32_t acc, uint32_t imm);
  uint32_t __arm_vcx2_u32(int coproc, uint32_t n, uint32_t imm);
  uint32_t __arm_vcx2a_u32(int coproc, uint32_t acc, uint32_t n, uint32_t imm);
  uint32_t __arm_vcx3_u32(int coproc, uint32_t n, uint32_t m, uint32_t imm);
  uint32_t __arm_vcx3a_u32(int coproc, uint32_t acc, uint32_t n, uint32_t m, 
uint32_t imm);
  
  uint64_t __arm_vcx1d_u64(int coproc, uint32_t imm);
  uint64_t __arm_vcx1da_u64(int coproc, uint64_t acc, uint32_t imm);
  uint64_t __arm_vcx2d_u64(int coproc, uint64_t m, uint32_t imm);
  uint64_t __arm_vcx2da_u64(int coproc, uint64_t acc, uint64_t m, uint32_t imm);
  uint64_t __arm_vcx3d_u64(int coproc, uint64_t n, uint64_t m, uint32_t imm);
  uint64_t __arm_vcx3da_u64(int coproc, uint64_t acc, uint64_t n, uint64_t m, 
uint32_t imm);

Since the semantics of CDE instructions is opaque to the compiler, the
ACLE intrinsics require dedicated LLVM IR intrinsics. The 64-bit and
32-bit variants share the same IR intrinsic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76298

Files:
  clang/include/clang/Basic/arm_cde.td
  clang/test/CodeGen/arm-cde-vfp.c
  clang/test/Sema/arm-cde-immediates.c
  clang/utils/TableGen/MveEmitter.cpp
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMInstrCDE.td
  llvm/test/CodeGen/Thumb2/cde-vfp.ll

Index: llvm/test/CodeGen/Thumb2/cde-vfp.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/cde-vfp.ll
@@ -0,0 +1,198 @@
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+cdecp0 -mattr=+cdecp1 -mattr=+mve -verify-machineinstrs -o - %s | FileCheck %s
+; RUN: llc -mtriple=thumbv8m.main -mattr=+cdecp0 -mattr=+cdecp1 -mattr=+fp-armv8d16sp -verify-machineinstrs -o - %s | FileCheck %s
+
+declare float @llvm.arm.cde.vcx1.f32(i32 immarg, i32 immarg)
+declare float @llvm.arm.cde.vcx1a.f32(i32 immarg, float, i32 immarg)
+declare float @llvm.arm.cde.vcx2.f32(i32 immarg, float, i32 immarg)
+declare float @llvm.arm.cde.vcx2a.f32(i32 immarg, float, float, i32 immarg)
+declare float @llvm.arm.cde.vcx3.f32(i32 immarg, float, float, i32 immarg)
+declare float @llvm.arm.cde.vcx3a.f32(i32 immarg, float, float, float, i32 immarg)
+
+declare double @llvm.arm.cde.vcx1.f64(i32 immarg, i32 immarg)
+declare double @llvm.arm.cde.vcx1a.f64(i32 immarg, double, i32 immarg)
+declare double @llvm.arm.cde.vcx2.f64(i32 immarg, double, i32 immarg)
+declare double @llvm.arm.cde.vcx2a.f64(i32 immarg, double, double, i32 immarg)
+declare double @llvm.arm.cde.vcx3.f64(i32 immarg, double, double, i32 immarg)
+declare double @llvm.arm.cde.vcx3a.f64(i32 immarg, double, double, double, i32 immarg)
+
+define arm_aapcs_vfpcc i32 @test_vcx1_u32() {
+; CHECK-LABEL: test_vcx1_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcx1 p0, s0, #11
+; CHECK-NEXT:vmov r0, s0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call float @llvm.arm.cde.vcx1.f32(i32 0, i32 11)
+  %1 = bitcast float %0 to i32
+  ret i32 %1
+}
+
+define arm_aapcs_vfpcc i32 @test_vcx1a_u32(i32 %acc) {
+; CHECK-LABEL: test_vcx1a_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmov s0, r0
+; CHECK-NEXT:vcx1a p1, s0, #12
+; CHECK-NEXT:vmov r0, s0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast i32 %acc to float
+  %1 = call float @llvm.arm.cde.vcx1a.f32(i32 1, float %0, i32 12)
+  %2 = bitcast float %1 to i32
+  ret i32 %2
+}
+
+define arm_aapcs_vfpcc i32 @test_vcx2_u32(i32 %n) {
+; CHECK-LABEL: test_vcx2_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmov s0, r0
+; CHECK-NEXT:vcx2 p0, s0, s0, #21
+; CHECK-NEXT:vmov r0, s0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast i32 %n to float
+  %1 = call float @llvm.arm.cde.vcx2.f32(i32 0, float %0, i32 21)
+  %2 = bitcast float %1 to i32
+  ret i32 %2
+}
+
+define arm_aapcs_vfpcc i32 @test_vcx2a_u32(i32 %acc, i32 %n) {
+; CHECK-LABEL: test_vcx2a_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmov s0, r1
+; CHECK-NEXT:vmov s2, r0
+; CHECK-NEXT:vcx2a p0, s2, s0, #22
+; CHECK-NEXT:vmov r0, s2
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast i32 %acc to float
+  %1 = bitcast i32 %n to float
+  %2 = call float @llvm.arm.cde.vcx2a.f32(i32 0, float %0, float %1, i32 22)
+  %3 = bitcast float %2 to i32
+  ret i32 %3
+}
+
+define arm_aapcs_vfpcc i32 @test_vc

[PATCH] D76297: [clang][AArch64] readd support for 'p' inline asm constraint

2020-03-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers marked an inline comment as done.
nickdesaulniers added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.h:98
   break;
-default:
-  R = std::string(1, *Constraint);
-  break;
 }
+return TargetInfo::convertConstraint(Constraint);

bah, need to return `R` for the previous case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76297



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


[PATCH] D76297: [clang][AArch64] readd support for 'p' inline asm constraint

2020-03-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 250812.
nickdesaulniers added a comment.

- fix 'U' case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76297

Files:
  clang/lib/Basic/Targets/AArch64.h
  clang/test/CodeGen/inline-asm-p-constraint.c


Index: clang/test/CodeGen/inline-asm-p-constraint.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-asm-p-constraint.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple aarch64-linux-gnu | FileCheck %s
+void foo(void* ptr) {
+  asm volatile("prfm pldl1keep, %a0\n" : : "p" (ptr));
+  // CHECK: call void asm sideeffect "prfm pldl1keep, ${0:a}\0A", "r"(i8* 
%0)
+  // CHECK-NOT: call void asm sideeffect "prfm pldl1keep, ${0:a}\0A", "p"(i8* 
%0)
+}
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -96,7 +96,7 @@
   Constraint += 2;
   break;
 default:
-  R = std::string(1, *Constraint);
+  R = TargetInfo::convertConstraint(Constraint);
   break;
 }
 return R;


Index: clang/test/CodeGen/inline-asm-p-constraint.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-asm-p-constraint.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple aarch64-linux-gnu | FileCheck %s
+void foo(void* ptr) {
+  asm volatile("prfm pldl1keep, %a0\n" : : "p" (ptr));
+  // CHECK: call void asm sideeffect "prfm pldl1keep, ${0:a}\0A", "r"(i8* %0)
+  // CHECK-NOT: call void asm sideeffect "prfm pldl1keep, ${0:a}\0A", "p"(i8* %0)
+}
Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -96,7 +96,7 @@
   Constraint += 2;
   break;
 default:
-  R = std::string(1, *Constraint);
+  R = TargetInfo::convertConstraint(Constraint);
   break;
 }
 return R;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76299: [ARM,CDE] Implement CDE unpredicated Q-register intrinsics

2020-03-17 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: simon_tatham, MarkMurrayARM, dmgreen, ostannard.
Herald added subscribers: cfe-commits, danielkiss, hiraditya, kristof.beyls.
Herald added a project: clang.
miyuki added a parent revision: D76298: [ARM,CDE] Implement CDE S and 
D-register intrinsics.

This patch implements the following intrinsics:

  uint8x16_t __arm_vcx1q_u8 (int coproc, uint32_t imm);
  T __arm_vcx1qa(int coproc, T acc, uint32_t imm);
  T __arm_vcx2q(int coproc, T n, uint32_t imm);
  uint8x16_t __arm_vcx2q_u8(int coproc, T n, uint32_t imm);
  T __arm_vcx2qa(int coproc, T acc, U n, uint32_t imm);
  T __arm_vcx3q(int coproc, T n, U m, uint32_t imm);
  uint8x16_t __arm_vcx3q_u8(int coproc, T n, U m, uint32_t imm);
  T __arm_vcx3qa(int coproc, T acc, U n, V m, uint32_t imm);

Most of them are polymorphic. Furthermore, some intrinsics are
polymorphic by 2 or 3 parameter types, such polymorphism is not
supported by the existing MVE/CDE tablegen backends, also we don't
really want to have a combinatorial explosion caused by 1000 different
combinations of 3 vector types. Because of this some intrinsics are
implemented as macros involving a cast of the polymorphic arguments to
uint8x16_t.

The IR intrinsics are even more restricted in terms of types: all MVE
vectors are cast to v16i8.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76299

Files:
  clang/include/clang/Basic/arm_cde.td
  clang/test/CodeGen/arm-cde-vec.c
  clang/test/Sema/arm-cde-immediates.c
  clang/utils/TableGen/MveEmitter.cpp
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMInstrCDE.td
  llvm/test/CodeGen/Thumb2/cde-vec.ll

Index: llvm/test/CodeGen/Thumb2/cde-vec.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/cde-vec.ll
@@ -0,0 +1,114 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+cdecp0 -mattr=+cdecp1 -mattr=+mve -verify-machineinstrs -o - %s | FileCheck %s
+
+declare <16 x i8> @llvm.arm.cde.vcx1q(i32 immarg, i32 immarg)
+declare <16 x i8> @llvm.arm.cde.vcx1qa(i32 immarg, <16 x i8>, i32 immarg)
+declare <16 x i8> @llvm.arm.cde.vcx2q(i32 immarg, <16 x i8>, i32 immarg)
+declare <16 x i8> @llvm.arm.cde.vcx2qa(i32 immarg, <16 x i8>, <16 x i8>, i32 immarg)
+declare <16 x i8> @llvm.arm.cde.vcx3q(i32 immarg, <16 x i8>, <16 x i8>, i32 immarg)
+declare <16 x i8> @llvm.arm.cde.vcx3qa(i32 immarg, <16 x i8>, <16 x i8>, <16 x i8>, i32 immarg)
+
+define arm_aapcs_vfpcc <16 x i8> @test_vcx1q_u8() {
+; CHECK-LABEL: test_vcx1q_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcx1 p0, q0, #
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call <16 x i8> @llvm.arm.cde.vcx1q(i32 0, i32 )
+  ret <16 x i8> %0
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vcx1qa_1(<16 x i8> %acc) {
+; CHECK-LABEL: test_vcx1qa_1:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcx1a p1, q0, #1112
+; CHECK-NEXT:bx lr
+entry:
+  %0 = call <16 x i8> @llvm.arm.cde.vcx1qa(i32 1, <16 x i8> %acc, i32 1112)
+  ret <16 x i8> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vcx1qa_2(<4 x i32> %acc) {
+; CHECK-LABEL: test_vcx1qa_2:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcx1a p0, q0, #1113
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast <4 x i32> %acc to <16 x i8>
+  %1 = call <16 x i8> @llvm.arm.cde.vcx1qa(i32 0, <16 x i8> %0, i32 1113)
+  %2 = bitcast <16 x i8> %1 to <4 x i32>
+  ret <4 x i32> %2
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vcx2q_u8(<8 x half> %n) {
+; CHECK-LABEL: test_vcx2q_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcx2 p1, q0, q0, #111
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast <8 x half> %n to <16 x i8>
+  %1 = call <16 x i8> @llvm.arm.cde.vcx2q(i32 1, <16 x i8> %0, i32 111)
+  ret <16 x i8> %1
+}
+
+define arm_aapcs_vfpcc <4 x float> @test_vcx2q(<4 x float> %n) {
+; CHECK-LABEL: test_vcx2q:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcx2 p1, q0, q0, #112
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast <4 x float> %n to <16 x i8>
+  %1 = call <16 x i8> @llvm.arm.cde.vcx2q(i32 1, <16 x i8> %0, i32 112)
+  %2 = bitcast <16 x i8> %1 to <4 x float>
+  ret <4 x float> %2
+}
+
+define arm_aapcs_vfpcc <4 x float> @test_vcx2qa(<4 x float> %acc, <2 x i64> %n) {
+; CHECK-LABEL: test_vcx2qa:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcx2a p0, q0, q1, #113
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast <4 x float> %acc to <16 x i8>
+  %1 = bitcast <2 x i64> %n to <16 x i8>
+  %2 = call <16 x i8> @llvm.arm.cde.vcx2qa(i32 0, <16 x i8> %0, <16 x i8> %1, i32 113)
+  %3 = bitcast <16 x i8> %2 to <4 x float>
+  ret <4 x float> %3
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vcx3q_u8(<8 x i16> %n, <4 x i32> %m) {
+; CHECK-LABEL: test_vcx3q_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcx3 p0, q0, q0, q1, #11
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast <8 x i16> %n to <16 x i8>
+  %1 = bitcast <4 x i32> %m to <16 x 

[PATCH] D75169: [ARM] Enforcing calling convention for half-precision FP arguments and returns for big-endian AArch32

2020-03-17 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D75169#1926545 , @pratlucas wrote:

> Hi @rjmccall,
>  I agree those kind of tweaks do not look good. The issue here, though, is 
> that argument coercion currently ignores the target's endian information when 
> performing coercion through memory.
>  This happens for any type that requires memory coercion, so unfortunately 
> using `[1 x i32]` does not do the trick.


Oh, wait, AAPCS wants half values to be passed in the *least* significant bits 
of a GPR, even on big-endian machines?  That's certainly more convenient, but 
it's a weird inconsistency with the otherwise iron rule of the calling 
convention, which that it's exactly as if you laid all of the arguments out in 
memory and then popped the first four 32-bit values off.  We're talking about a 
calling convention here that literally skips registers in order to "align" 
arguments.

Can we not just coerce to i16?  Will LLVM not pass an i16 in the 
least-significant bits of a register?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75169



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


[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-17 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361



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


[PATCH] D76283: [IRBuilder] Use preferred target type for len argument of memory intrinsic functions

2020-03-17 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I guess the logical rule would be that the bit-width of the size has to match 
the minimum of the bit-widths of the address spaces used with the intrinsic.  
(Note that `llvm.memcpy` etc. can take pointers into two different address 
spaces, potentially of different widths.)  That might be pretty disruptive for 
existing code, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76283



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


[PATCH] D59214: [clang][OpeMP] Model OpenMP structured-block in AST (PR40563)

2020-03-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D59214#1919183 , @lebedev.ri wrote:

> d5edcb90643104d6911da5c0ff44c4f33fff992f 
> , 
> looking forward to seeing better error recovery.


Thanks very much for your help Roman, I'm also sorry this has been difficult.

The plan for error recovery is to add a RecoveryExpr to the AST that can 
represent the known structure of an invalid expression (e.g. a function call 
with no viable overloads - this has subexpressions and possibly a known type) 
instead of dropping it as we do today. This will be used to improve diagnostics 
and also expose a more meaningful AST to tools.

A "transitive-has-errors" bit on Expr is needed as various places currently 
assume that if an Expr exists, the code is valid. (TypoExpr is a complicated 
special snowflake, and we should also be able to reduce the number of places 
that special-case it).


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59214



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


[PATCH] D73898: [analyzer] StdLibraryFunctionsChecker: Add argument constraints

2020-03-17 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 16 inline comments as done.
martong added inline comments.
Herald added a subscriber: DenisDvlp.



Comment at: clang/include/clang/StaticAnalyzer/Checkers/Checkers.td:296
+def StdCLibraryFunctionArgsChecker : Checker<"StdCLibraryFunctionArgs">,
+  HelpText<"Check constraints of arguments of C standard library functions">,
+  Dependencies<[StdCLibraryFunctionsChecker]>,

Szelethus wrote:
> martong wrote:
> > Szelethus wrote:
> > > How about we add an example as well?
> > You mean like NonNull or other constraints?
> Like
> ```
> Check constraints of arguments of C standard library functions, such as 
> whether the parameter of isalpha is in the range [0, 255] or is EOF.
> ```
Ok, done.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:191
+  ///   * a list of branches - a list of list of ranges -
+  /// i.e. a list of lists of lists of segments,
+  ///   * a list of argument constraints, that must be true on every branch.

martong wrote:
> Szelethus wrote:
> > I think that is a rather poor example to help understand what `list of list 
> > of ranges` means :) -- Could you try to find something better?
> Yeah, that part definitely should be reworded.
I added an example with `isalpha`.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:92-93
 
+  class ValueConstraint;
+  using ValueConstraintPtr = std::shared_ptr;
   class ValueConstraint {

Szelethus wrote:
> How about `ValueConstraintRef`?
Yeah, we have `ProgramStateRef` and `SymbolRef`. And both are actually just 
synonyms to smart pointers. I'd rather not call a pointer as a reference, 
because that can be confusing when reading the code. E.g. when I see that we 
return with a `nullptr` from a function that can return with a `...Ref` I start 
to scratch my head.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:399-407
+  auto Report = [&](ExplodedNode *N) {
+if (!ChecksEnabled[CK_StdCLibraryFunctionArgsChecker])
+  return;
+// FIXME Add detailed diagnostic.
+StringRef Msg = "Function argument constraint is not satisfied";
+auto R = std::make_unique(BT, Msg, N);
+bugreporter::trackExpressionValue(N, Call.getArgExpr(0), *R);

Szelethus wrote:
> While I find your usage of lambdas fascinating, this one seems a bit 
> unnecessary :)
Ok I moved it to be a member function named `ReportBug`.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:409
 
-  Optional FoundSummary = findFunctionSummary(FD, CE, C);
+  for (const ValueConstraintPtr& VC : Summary.ArgConstraints) {
+ProgramStateRef SuccessSt = VC->apply(State, Call, Summary);

NoQ wrote:
> Maybe we should add an assertion that the same argument isn't specified 
> multiple times.
I think there could be cases when we want to have e.g. a not-null constraint on 
the 1st argument, but also we want to express that the 1st argument's size is 
described by the 2nd argument. I am planning to implement such a constraints in 
the future. In that case we would have two constraints on the 1st argument and 
the assert would fire.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73898



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


[PATCH] D73898: [analyzer] StdLibraryFunctionsChecker: Add argument constraints

2020-03-17 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 250820.
martong marked 4 inline comments as done.
martong removed a subscriber: DenisDvlp.
martong added a comment.

- Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73898

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/std-c-library-functions-arg-constraints-bug-path.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions.c

Index: clang/test/Analysis/std-c-library-functions.c
===
--- clang/test/Analysis/std-c-library-functions.c
+++ clang/test/Analysis/std-c-library-functions.c
@@ -1,8 +1,34 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple x86_64-unknown-linux \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple armv7-a15-linux \
+// RUN:   -verify
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple thumbv7-a15-linux \
+// RUN:   -verify
 
 void clang_analyzer_eval(int);
 
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -0,0 +1,44 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu \
+// RUN:   -verify
+
+void clang_analyzer_eval(int);
+
+int glob;
+
+#define EOF -1
+
+int isalnum(int);
+
+void test_alnum_concrete(int v) {
+  int ret = isalnum(256); // expected-warning{{Function argument constraint is not satisfied}}
+  (void)ret;
+}
+
+void test_alnum_symbolic(int x) {
+  int ret = isalnum(x);
+  (void)ret;
+  clang_analyzer_eval(EOF <= x && x <= 255); // expected-warning{{TRUE}}
+}
+
+void test_alnum_symbolic2(int x) {
+  if (x > 255) {
+int ret = isalnum(x); // expected-warning{{Function argument constraint is not satisfied}}
+(void)ret;
+  }
+}
+
+void test_alnum_infeasible_path(int x, int y) {
+  int ret = isalnum(x);
+  y = 0;
+  clang_analyzer_eval(EOF <= x && x <= 255); // expected-warning{{TRUE}}
+
+  if (x > 255) // This path is no longer feasible.
+ret = x / y; // No warning here
+
+  ret = x / y; // expected-warning{{Division by zero}}
+}
Index: clang/test/Analysis/std-c-library-functions-arg-constraints-bug-path.c
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-arg-constraints-bug-path.c
@@ -0,0 +1,29 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu \
+// RUN:   -analyzer-ou

[PATCH] D76300: [ARM,CDE] Implement CDE vreinterpret intrinsics

2020-03-17 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: simon_tatham, MarkMurrayARM, dmgreen, ostannard.
Herald added subscribers: cfe-commits, danielkiss, kristof.beyls.
Herald added a project: clang.
miyuki added a parent revision: D76299: [ARM,CDE] Implement CDE unpredicated 
Q-register intrinsics.

This patch implements the following CDE intrinsics:

  int8x16_t __arm_vreinterpretq_s8_u8 (uint8x16_t in);
  uint16x8_t __arm_vreinterpretq_u16_u8 (uint8x16_t in);
  int16x8_t __arm_vreinterpretq_s16_u8 (uint8x16_t in);
  uint32x4_t __arm_vreinterpretq_u32_u8 (uint8x16_t in);
  int32x4_t __arm_vreinterpretq_s32_u8 (uint8x16_t in);
  uint64x2_t __arm_vreinterpretq_u64_u8 (uint8x16_t in);
  int64x2_t __arm_vreinterpretq_s64_u8 (uint8x16_t in);
  float16x8_t __arm_vreinterpretq_f16_u8 (uint8x16_t in);
  float32x4_t __arm_vreinterpretq_f32_u8 (uint8x16_t in);

These intrinsics are header-only because they reuse the existing
MVE vreinterpret clang built-ins.

This set is slightly different from the published specification
(see https://static.docs.arm.com/101028/0010/ACLE_2019Q4_release-0010.pdf):
it includes

  int8x16_t __arm_vreinterpretq_s8_u8 (uint8x16_t in);

which was unintentionally ommitted from the spec, and
does not include

  float64x2_t __arm_vreinterpretq_f64_u8 (uint8x16_t in);

The float64x2_t type requires additional implementation
effort, and we are not including it yet.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76300

Files:
  clang/include/clang/Basic/arm_cde.td
  clang/test/CodeGen/arm-cde-reinterpret.c


Index: clang/test/CodeGen/arm-cde-reinterpret.c
===
--- /dev/null
+++ clang/test/CodeGen/arm-cde-reinterpret.c
@@ -0,0 +1,78 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi \
+// RUN:   -target-feature +cdecp0 -target-feature +mve.fp \
+// RUN:   -mfloat-abi hard -O0 -disable-O0-optnone \
+// RUN:   -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @test_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <16 x i8> [[X:%.*]]
+//
+int8x16_t test_s8(uint8x16_t x) {
+  return __arm_vreinterpretq_s8_u8(x);
+}
+
+// CHECK-LABEL: @test_u16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x i16>
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+uint16x8_t test_u16(uint8x16_t x) {
+  return __arm_vreinterpretq_u16_u8(x);
+}
+
+// CHECK-LABEL: @test_s32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+int32x4_t test_s32(uint8x16_t x) {
+  return __arm_vreinterpretq_s32_u8(x);
+}
+
+// CHECK-LABEL: @test_u32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x i32>
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+uint32x4_t test_u32(uint8x16_t x) {
+  return __arm_vreinterpretq_u32_u8(x);
+}
+
+// CHECK-LABEL: @test_s64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-NEXT:ret <2 x i64> [[TMP0]]
+//
+int64x2_t test_s64(uint8x16_t x) {
+  return __arm_vreinterpretq_s64_u8(x);
+}
+
+// CHECK-LABEL: @test_u64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <2 x i64>
+// CHECK-NEXT:ret <2 x i64> [[TMP0]]
+//
+uint64x2_t test_u64(uint8x16_t x) {
+  return __arm_vreinterpretq_u64_u8(x);
+}
+
+// CHECK-LABEL: @test_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <8 x half>
+// CHECK-NEXT:ret <8 x half> [[TMP0]]
+//
+float16x8_t test_f16(uint8x16_t x) {
+  return __arm_vreinterpretq_f16_u8(x);
+}
+
+// CHECK-LABEL: @test_f32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[X:%.*]] to <4 x float>
+// CHECK-NEXT:ret <4 x float> [[TMP0]]
+//
+float32x4_t test_f32(uint8x16_t x) {
+  return __arm_vreinterpretq_f32_u8(x);
+}
Index: clang/include/clang/Basic/arm_cde.td
===
--- clang/include/clang/Basic/arm_cde.td
+++ clang/include/clang/Basic/arm_cde.td
@@ -188,3 +188,11 @@
   ["cp", "acc", "n", "m", "imm"],
   "__arm_vcx3qa_impl((cp), (acc), __arm_vreinterpretq_u8(n), "
  "__arm_vreinterpretq_u8(m), (imm))">;
+
+// vreinterpretq intrinsics required by the ACLE CDE specification
+
+foreach desttype = [/* no u8 */ s8, u16, s16, u32, s32, u64, s64, f16, f32] in 
{
+  let params = [u8], headerOnly = 1, pnt = PNT_None in
+  def "vreinterpretq_" # desttype : Intrinsic<
+VecOf, (args Vector:$x), (vreinterpret $x, VecOf)>;
+}


Index: clang/test/CodeGen/arm-cde-reinterpret.c
===
--- /dev/null
+++ clang/test/CodeGen/arm-cde-reinterpret.c
@@ -0,0 +1,78 @@
+// NOTE: Assertions have been autogenerate

  1   2   3   >