[PATCH] D90507: [Driver] Add DWARF64 flag: -gdwarf64

2020-12-20 Thread Igor Kudrin via Phabricator via cfe-commits
ikudrin added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4016
 
+  auto *dwarfArgs =
+  Args.getLastArg(options::OPT_gdwarf64, options::OPT_gdwarf32);

Maybe make this more descriptive?



Comment at: clang/test/Driver/debug-options.c:391
+// GDWARF64_ON:  "-gdwarf64"
+// GDWARF64_OFF:  error: invalid argument '-gdwarf64' only allowed with 
'DWARFv3 or greater'
+// GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 
bit architecture'




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90507

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


[PATCH] D90329: [PowerPC] Fix va_arg in C++, Objective-C on 32-bit ELF targets

2020-12-20 Thread George Koehler via Phabricator via cfe-commits
kernigh added a comment.

Hi, Eli. I'm missing emails from Phabricator, so I didn't know about your 
recent post. I will respond to your question about numUsedRegs when I find time.


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

https://reviews.llvm.org/D90329

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


[PATCH] D92006: Refactoring the attribute plugin example to fit the new API

2020-12-20 Thread Yafei Liu via Phabricator via cfe-commits
psionic12 marked an inline comment as done.
psionic12 added a comment.

Hi, could anyone help to commit this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92006

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


[clang] db1616c - [test] Fix new-pass-manager-opt-bisect.c

2020-12-20 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2020-12-20T17:13:42-08:00
New Revision: db1616c768475545453cf025d774db8d47f39ce3

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

LOG: [test] Fix new-pass-manager-opt-bisect.c

Requires x86 target to be registered.

Added: 


Modified: 
clang/test/CodeGen/new-pass-manager-opt-bisect.c

Removed: 




diff  --git a/clang/test/CodeGen/new-pass-manager-opt-bisect.c 
b/clang/test/CodeGen/new-pass-manager-opt-bisect.c
index 30c4a36802a1..f070cb898467 100644
--- a/clang/test/CodeGen/new-pass-manager-opt-bisect.c
+++ b/clang/test/CodeGen/new-pass-manager-opt-bisect.c
@@ -1,3 +1,5 @@
+// REQUIRES: x86-registered-target
+
 // Make sure opt-bisect works through both pass managers
 //
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 
-fexperimental-new-pass-manager %s -mllvm -opt-bisect-limit=-1 -emit-obj -o 
/dev/null 2>&1 | FileCheck %s



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


[PATCH] D93452: [clangd] Trim memory periodically

2020-12-20 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau added a comment.

Here is the latest version, I believe it should mostly look like what you 
expect. Let me know if there is anything that you'd like me to change, it's 
totally fine to have a few more iterations on this diff.

I added a `CLANGD_ENABLE_MEMORY_CLEANUP` to make sure people can work around 
some weird linking issues with `malloc_trim` if necessary. I've noticed options 
such as `CLANGD_ENABLE_REMOTE` also appear in the files below, but as I have no 
idea what they are for, I did not add `CLANGD_ENABLE_MEMORY_CLEANUP` to them. 
Let me know if I should do anything concerning these files.

- clang-tools-extra/clangd/test/lit.site.cfg.py.in
- llvm/utils/gn/secondary/clang-tools-extra/clangd/BUILD.gn
- llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93452

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


[PATCH] D93452: [clangd] Trim memory periodically

2020-12-20 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau updated this revision to Diff 313000.
qchateau marked 16 inline comments as done.
qchateau added a comment.



- Move platform specific code to ClangdMain
- Generic memory cleanup callback in ClangdLSPServer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93452

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/Features.inc.in
  clang-tools-extra/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -50,6 +50,10 @@
 #include 
 #endif
 
+#ifdef __GLIBC__
+#include 
+#endif
+
 namespace clang {
 namespace clangd {
 
@@ -497,6 +501,15 @@
 init(ClangdServer::Options().CollectMainFileRefs),
 };
 
+#if CLANGD_ENABLE_MEMORY_CLEANUP
+opt EnableMemoryCleanup{
+"memory-cleanup",
+cat(Misc),
+desc("Perform periodic memory cleanup."),
+init(true),
+};
+#endif // CLANGD_ENABLE_MEMORY_CLEANUP
+
 #if CLANGD_ENABLE_REMOTE
 opt RemoteIndexAddress{
 "remote-index-address",
@@ -577,6 +590,20 @@
   }
   llvm_unreachable("Invalid ExternalIndexKind.");
 }
+
+#if CLANGD_ENABLE_MEMORY_CLEANUP
+std::function getMemoryCleanupFunction() {
+#ifdef __GLIBC__
+  // Leave a few MB at the top of the heap: it is insignificant
+  // and will most likely be needed by the main thread
+  constexpr size_t MallocTrimPad = 20'000'000;
+  return []() { malloc_trim(MallocTrimPad); };
+#else
+  return {};
+#endif
+}
+#endif // CLANGD_ENABLE_MEMORY_CLEANUP
+
 } // namespace
 } // namespace clangd
 } // namespace clang
@@ -797,6 +824,10 @@
   Opts.BuildRecoveryAST = RecoveryAST;
   Opts.PreserveRecoveryASTType = RecoveryASTType;
   Opts.FoldingRanges = FoldingRanges;
+#if CLANGD_ENABLE_MEMORY_CLEANUP
+  if (EnableMemoryCleanup)
+Opts.MemoryCleanup = getMemoryCleanupFunction();
+#endif // CLANGD_ENABLE_MEMORY_CLEANUP
 
   Opts.CodeComplete.IncludeIneligibleResults = IncludeIneligibleResults;
   Opts.CodeComplete.Limit = LimitResults;
Index: clang-tools-extra/clangd/Features.inc.in
===
--- clang-tools-extra/clangd/Features.inc.in
+++ clang-tools-extra/clangd/Features.inc.in
@@ -1,2 +1,3 @@
 #define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
 #define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@
+#define CLANGD_ENABLE_MEMORY_CLEANUP @CLANGD_ENABLE_MEMORY_CLEANUP@
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -48,6 +48,9 @@
 llvm::Optional CompileCommandsDir;
 /// The offset-encoding to use, or None to negotiate it over LSP.
 llvm::Optional Encoding;
+/// If set, periodically called to release memory.
+/// Consider malloc_trim(3)
+std::function MemoryCleanup = nullptr;
 
 /// Per-feature options. Generally ClangdServer lets these vary
 /// per-request, but LSP allows limited/no customizations.
@@ -184,10 +187,18 @@
   /// profiling hasn't happened recently.
   void maybeExportMemoryProfile();
 
+  /// Run the MemoryCleanup callback if it's time.
+  /// This method is thread safe.
+  void maybeCleanupMemory();
+
   /// Timepoint until which profiling is off. It is used to throttle profiling
   /// requests.
   std::chrono::steady_clock::time_point NextProfileTime;
 
+  /// Next time we want to call the MemoryCleanup callback.
+  std::mutex NextMemoryCleanupTimeMutex;
+  std::chrono::steady_clock::time_point NextMemoryCleanupTime;
+
   /// Since initialization of CDBs and ClangdServer is done lazily, the
   /// following context captures the one used while creating ClangdLSPServer and
   /// passes it to above mentioned object instances to make sure they share the
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -178,6 +178,7 @@
 } else if (auto Handler = Notifications.lookup(Method)) {
   Handler(std::move(Params));
   Server.maybeExportMemoryProfile();
+  Server.maybeCleanupMemory();
 } else {
   log("unhandled notification {0}", Method);
 }
@@ -453,6 +454,7 @@
 
 void ClangdLSPServer::notify(llvm::StringRef Method, llvm::json::Value Params) {
   log("--> {0}", Method);
+  maybeCleanupMemory();
   std::lock_guard Lock(TranspWriter);
   Transp.notify(Method, std::move(Params));
 }
@@ -1295,6 +1297,27 @@
   NextProfileTime = Now + ProfileInterval;
 }
 
+void ClangdLSPServer::maybeCleanupMemory() {
+  // Memory cleanup is probably expensive, throttle it
+  static constexpr auto 

[PATCH] D92897: Make NPM OptBisectInstrumentation use global singleton OptBisect

2020-12-20 Thread Arthur Eubanks via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG47dbee6790cb: Make NPM OptBisectInstrumentation use global 
singleton OptBisect (authored by swamulism, committed by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92897

Files:
  clang/test/CodeGen/new-pass-manager-opt-bisect.c
  llvm/include/llvm/IR/OptBisect.h
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/lib/IR/LLVMContextImpl.cpp
  llvm/lib/IR/OptBisect.cpp
  llvm/lib/Passes/StandardInstrumentations.cpp

Index: llvm/lib/Passes/StandardInstrumentations.cpp
===
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ llvm/lib/Passes/StandardInstrumentations.cpp
@@ -624,11 +624,11 @@
 
 void OptBisectInstrumentation::registerCallbacks(
 PassInstrumentationCallbacks ) {
-  if (!isEnabled())
+  if (!OptBisector->isEnabled())
 return;
-
-  PIC.registerShouldRunOptionalPassCallback([this](StringRef PassID, Any IR) {
-return isIgnored(PassID) || checkPass(PassID, getBisectDescription(IR));
+  PIC.registerShouldRunOptionalPassCallback([](StringRef PassID, Any IR) {
+return isIgnored(PassID) ||
+   OptBisector->checkPass(PassID, getBisectDescription(IR));
   });
 }
 
Index: llvm/lib/IR/OptBisect.cpp
===
--- llvm/lib/IR/OptBisect.cpp
+++ llvm/lib/IR/OptBisect.cpp
@@ -54,3 +54,5 @@
   printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun);
   return ShouldRun;
 }
+
+ManagedStatic llvm::OptBisector;
Index: llvm/lib/IR/LLVMContextImpl.cpp
===
--- llvm/lib/IR/LLVMContextImpl.cpp
+++ llvm/lib/IR/LLVMContextImpl.cpp
@@ -219,19 +219,8 @@
 SSNs[SSE.second] = SSE.first();
 }
 
-/// Singleton instance of the OptBisect class.
-///
-/// This singleton is accessed via the LLVMContext::getOptPassGate() function.
-/// It provides a mechanism to disable passes and individual optimizations at
-/// compile time based on a command line option (-opt-bisect-limit) in order to
-/// perform a bisecting search for optimization-related problems.
-///
-/// Even if multiple LLVMContext objects are created, they will all return the
-/// same instance of OptBisect in order to provide a single bisect count.  Any
-/// code that uses the OptBisect object should be serialized when bisection is
-/// enabled in order to enable a consistent bisect count.
-static ManagedStatic OptBisector;
-
+/// Gets the OptPassGate for this LLVMContextImpl, which defaults to the
+/// singleton OptBisect if not explicitly set.
 OptPassGate ::getOptPassGate() const {
   if (!OPG)
 OPG = &(*OptBisector);
Index: llvm/include/llvm/Passes/StandardInstrumentations.h
===
--- llvm/include/llvm/Passes/StandardInstrumentations.h
+++ llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -72,7 +72,7 @@
   bool shouldRun(StringRef PassID, Any IR);
 };
 
-class OptBisectInstrumentation : public OptBisect {
+class OptBisectInstrumentation {
 public:
   OptBisectInstrumentation() {}
   void registerCallbacks(PassInstrumentationCallbacks );
Index: llvm/include/llvm/IR/OptBisect.h
===
--- llvm/include/llvm/IR/OptBisect.h
+++ llvm/include/llvm/IR/OptBisect.h
@@ -15,6 +15,7 @@
 #define LLVM_IR_OPTBISECT_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ManagedStatic.h"
 
 namespace llvm {
 
@@ -32,7 +33,7 @@
 return true;
   }
 
-  /// isEnabled should return true before calling shouldRunPass
+  /// isEnabled() should return true before calling shouldRunPass().
   virtual bool isEnabled() const { return false; }
 };
 
@@ -53,6 +54,14 @@
 
   virtual ~OptBisect() = default;
 
+  /// Checks the bisect limit to determine if the specified pass should run.
+  ///
+  /// This forwards to checkPass().
+  bool shouldRunPass(const Pass *P, StringRef IRDescription) override;
+
+  /// isEnabled() should return true before calling shouldRunPass().
+  bool isEnabled() const override { return BisectEnabled; }
+
   /// Checks the bisect limit to determine if the specified pass should run.
   ///
   /// If the bisect limit is set to -1, the function prints a message describing
@@ -64,12 +73,6 @@
   /// Most passes should not call this routine directly. Instead, they are
   /// called through helper routines provided by the pass base classes.  For
   /// instance, function passes should call FunctionPass::skipFunction().
-  bool shouldRunPass(const Pass *P, StringRef IRDescription) override;
-
-  /// isEnabled should return true before calling shouldRunPass
-  bool isEnabled() const override { return BisectEnabled; }
-
-protected:
   bool checkPass(const StringRef PassName, 

[clang] 47dbee6 - Make NPM OptBisectInstrumentation use global singleton OptBisect

2020-12-20 Thread Arthur Eubanks via cfe-commits

Author: Samuel Eubanks
Date: 2020-12-20T13:47:56-08:00
New Revision: 47dbee6790cb813e4f4bc993585b9770c357e508

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

LOG: Make NPM OptBisectInstrumentation use global singleton OptBisect

Currently there is an issue where the legacy pass manager uses a different 
OptBisect counter than the new pass manager.
This fix makes the npm OptBisectInstrumentation use the global OptBisect.

Reviewed By: aeubanks

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

Added: 
clang/test/CodeGen/new-pass-manager-opt-bisect.c

Modified: 
llvm/include/llvm/IR/OptBisect.h
llvm/include/llvm/Passes/StandardInstrumentations.h
llvm/lib/IR/LLVMContextImpl.cpp
llvm/lib/IR/OptBisect.cpp
llvm/lib/Passes/StandardInstrumentations.cpp

Removed: 




diff  --git a/clang/test/CodeGen/new-pass-manager-opt-bisect.c 
b/clang/test/CodeGen/new-pass-manager-opt-bisect.c
new file mode 100644
index ..30c4a36802a1
--- /dev/null
+++ b/clang/test/CodeGen/new-pass-manager-opt-bisect.c
@@ -0,0 +1,10 @@
+// Make sure opt-bisect works through both pass managers
+//
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 
-fexperimental-new-pass-manager %s -mllvm -opt-bisect-limit=-1 -emit-obj -o 
/dev/null 2>&1 | FileCheck %s
+
+// CHECK: BISECT: running pass (1)
+// CHECK-NOT: BISECT: running pass (1)
+// Make sure that legacy pass manager is running
+// CHECK: Instruction Selection
+
+int func(int a) { return a; }

diff  --git a/llvm/include/llvm/IR/OptBisect.h 
b/llvm/include/llvm/IR/OptBisect.h
index 5371d88fbb7d..6c2a1b01d897 100644
--- a/llvm/include/llvm/IR/OptBisect.h
+++ b/llvm/include/llvm/IR/OptBisect.h
@@ -15,6 +15,7 @@
 #define LLVM_IR_OPTBISECT_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ManagedStatic.h"
 
 namespace llvm {
 
@@ -32,7 +33,7 @@ class OptPassGate {
 return true;
   }
 
-  /// isEnabled should return true before calling shouldRunPass
+  /// isEnabled() should return true before calling shouldRunPass().
   virtual bool isEnabled() const { return false; }
 };
 
@@ -53,6 +54,14 @@ class OptBisect : public OptPassGate {
 
   virtual ~OptBisect() = default;
 
+  /// Checks the bisect limit to determine if the specified pass should run.
+  ///
+  /// This forwards to checkPass().
+  bool shouldRunPass(const Pass *P, StringRef IRDescription) override;
+
+  /// isEnabled() should return true before calling shouldRunPass().
+  bool isEnabled() const override { return BisectEnabled; }
+
   /// Checks the bisect limit to determine if the specified pass should run.
   ///
   /// If the bisect limit is set to -1, the function prints a message 
describing
@@ -64,12 +73,6 @@ class OptBisect : public OptPassGate {
   /// Most passes should not call this routine directly. Instead, they are
   /// called through helper routines provided by the pass base classes.  For
   /// instance, function passes should call FunctionPass::skipFunction().
-  bool shouldRunPass(const Pass *P, StringRef IRDescription) override;
-
-  /// isEnabled should return true before calling shouldRunPass
-  bool isEnabled() const override { return BisectEnabled; }
-
-protected:
   bool checkPass(const StringRef PassName, const StringRef TargetDesc);
 
 private:
@@ -77,6 +80,9 @@ class OptBisect : public OptPassGate {
   unsigned LastBisectNum = 0;
 };
 
+/// Singleton instance of the OptBisect class, so multiple pass managers don't
+/// need to coordinate their uses of OptBisect.
+extern ManagedStatic OptBisector;
 } // end namespace llvm
 
 #endif // LLVM_IR_OPTBISECT_H

diff  --git a/llvm/include/llvm/Passes/StandardInstrumentations.h 
b/llvm/include/llvm/Passes/StandardInstrumentations.h
index c816c3fc2ab9..42751beb0685 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -72,7 +72,7 @@ class OptNoneInstrumentation {
   bool shouldRun(StringRef PassID, Any IR);
 };
 
-class OptBisectInstrumentation : public OptBisect {
+class OptBisectInstrumentation {
 public:
   OptBisectInstrumentation() {}
   void registerCallbacks(PassInstrumentationCallbacks );

diff  --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index 875c61cda423..93a0590e236c 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -219,19 +219,8 @@ void LLVMContextImpl::getSyncScopeNames(
 SSNs[SSE.second] = SSE.first();
 }
 
-/// Singleton instance of the OptBisect class.
-///
-/// This singleton is accessed via the LLVMContext::getOptPassGate() function.
-/// It provides a mechanism to disable passes and individual optimizations at
-/// compile time based on a command line option (-opt-bisect-limit) in order to
-/// perform a bisecting search for 

[PATCH] D93595: [analyzer] Fix extraction of punned and known scalar SVals

2020-12-20 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Based on a suggestion from Balazs, I reduced the scope of the initial change to 
just scalars. There is one issue I'd like to hear comments on, and that's how 
to handle the case of extracting a bit field outside of the represented APInt. 
Currently, I'm returning UnknownVal(), following the lead in RegionStore.cpp, 
line 1775, in method getBindingForElement. During development, I hit an assert 
in extractBits when encountering a "negative" case exposed by the LIT 
ptr-arith.cpp - the negative case being an index out of bounds of the punned 
scalar (see the LIT I added for the negative cases).

Based on this change, some of the basic structure cases are "working" (meaning 
not showing false results), but the change is probably not comprehensive 
enough, and definitely not covered well enough by tests, so focusing just on 
scalars for now. I'm willing to work on this collaboratively to solve these 
problems, since we encounter these analyzing our source code.




Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1657
+return SVB.makeIntVal(bits, true);
+  }
+  return UnknownVal();

I added this if to handle the case of something like this:

unsigned short sh = 0x1122;
unsigned char *p = (unsigned char *)

unsigned char aa = p[0];  This is ok, and will yield 0x11 or 0x22 - 
depending on endianess.
unsigned char ch = p[3];  This is an error and should be caught.

I opted with returning UnknownVal() following the lead in RegionStore.cpp:1775 
(just below). The negative test cases I added assume this. The ptr-arith.cpp 
LIT exposed this issue. Otherwise, I hit an assert in extractBits that the bit 
field is outside of represented range in the APInt. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93595

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


[PATCH] D93452: [clangd] Trim memory periodically

2020-12-20 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau added a comment.

> Sorry to mess you around like this, but I think I might have jumped the gun 
> in asking this to be abstracted away in `Process.h`.

No problem, there is not much code anyway. The thought process behind the 
"right" solution is by far the most important.

> So I think my favorite option may be back to:
>
> - Have ClangdLSPServer::Options take a nullable `std::function` to 
> abstract the (optional) platform-specific operation
> - Have ClangdMain contain platform #ifdefs and define+inject the wrapper that 
> calls `malloc_trim`
> - Optionally: have a clangd or cmake flag to disable this even if glibc was 
> detected. This provides a workaround for other allocators if we need it.

I'll go back to this then, and add all the other changes you suggested

---

In the meantime, I've done some testing with tcmalloc and jemalloc.

`jemalloc` does very good in this situation, the RSS goes down as soon as the 
memory is not required anymore:

- RSS goes down when the file is done parsing
- RSS goes down as soon as I close the file in VSCode

`tcmalloc` does fine, but is not ideal, the RSS does not grow to an 
unreasonable size, but does not go down when we release resources. It basically 
plateaus at the maximum usage (meaning what you use when parsing N files, N 
depending on the parallelism level). I'm not an expert on `tcmalloc` but from 
what I found it's supposed to release resources over time, which I failed to 
observe. `tcmalloc` does have an extension to actively release memory 
(`MallocExtension::instance()->ReleaseFreeMemory()`) which works as expected, 
bringing the RSS down. That being said, I'm not sure we need to do something 
about it, clangd will indeed waste a significant amount of RAM in this case, 
but [1] the usage is still reasonable and bounded and [2] it seems known that 
`tcmalloc` is a greedy allocator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93452

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


[PATCH] D93595: [analyzer] Fix extraction of punned and known SVals

2020-12-20 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 312996.
vabridgers added a comment.

Reduce scope of this initial change to just scalars


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93595

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/concrete-endian.cpp

Index: clang/test/Analysis/concrete-endian.cpp
===
--- /dev/null
+++ clang/test/Analysis/concrete-endian.cpp
@@ -0,0 +1,201 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-unknown-linux-gnu -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple powerpc64-unknown-linux-gnu  -verify %s
+
+void clang_analyzer_dump(int);
+void clang_analyzer_eval(int);
+
+int testLocConcreteInts() {
+  static_assert(sizeof(char) == 1, "test assumes sizeof(char) is 1");
+  static_assert(sizeof(short) == 2, "test assumes sizeof(short) is 2");
+  static_assert(sizeof(int) == 4, "test assumes sizeof(int) is 4");
+  static_assert(sizeof(long) == 8, "test assumes sizeof(long) is 8");
+  static_assert(sizeof(long *) == 8, "test assumes sizeof(long *) is 8");
+  long *p = (long *)0x11223344AA998877ULL;
+  unsigned char *ppb = (unsigned char *)
+  unsigned short *pps = (unsigned short *)
+  unsigned int *ppi = (unsigned int *)
+
+#if defined(__LITTLE_ENDIAN__)
+  clang_analyzer_eval(ppb[0] == 0x77); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[1] == 0x88); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[2] == 0x99); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[3] == 0xaa); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[4] == 0x44); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[5] == 0x33); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[6] == 0x22); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[7] == 0x11); // expected-warning{{TRUE}}
+#elif defined(__BIG_ENDIAN__)
+  clang_analyzer_eval(ppb[7] == 0x77);// expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[6] == 0x88);// expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[5] == 0x99);// expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[4] == 0xaa);// expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[3] == 0x44);// expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[2] == 0x33);// expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[1] == 0x22);// expected-warning{{TRUE}}
+  clang_analyzer_eval(ppb[0] == 0x11);// expected-warning{{TRUE}}
+#else
+#error "Don't recognize the endianess of this target!"
+#endif
+  // Array out of bounds should yield UNKNOWN
+  clang_analyzer_eval(ppb[8]);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(ppb[-1]); // expected-warning{{UNKNOWN}}
+
+#if defined(__LITTLE_ENDIAN__)
+  clang_analyzer_eval(pps[0] == 0x8877); // expected-warning{{TRUE}}
+  clang_analyzer_eval(pps[1] == 0xaa99); // expected-warning{{TRUE}}
+  clang_analyzer_eval(pps[2] == 0x3344); // expected-warning{{TRUE}}
+  clang_analyzer_eval(pps[3] == 0x1122); // expected-warning{{TRUE}}
+#elif defined(__BIG_ENDIAN__)
+  clang_analyzer_eval(pps[3] == 0x8877);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(pps[2] == 0xaa99);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(pps[1] == 0x3344);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(pps[0] == 0x1122);  // expected-warning{{TRUE}}
+#else
+#error "Don't recognize the endianess of this target!"
+#endif
+  // Array out of bounds should yield UNKNOWN
+  clang_analyzer_eval(pps[4]);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(pps[-1]); // expected-warning{{UNKNOWN}}
+
+#if defined(__LITTLE_ENDIAN__)
+  clang_analyzer_eval(ppi[0] == 0xaa998877); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ppi[1] == 0x11223344); // expected-warning{{TRUE}}
+#elif defined(__BIG_ENDIAN__)
+  clang_analyzer_eval(ppi[0] == 0x11223344);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(ppi[1] == 0xaa998877);  // expected-warning{{TRUE}}
+#else
+#error "Don't recognize the endianess of this target!"
+#endif
+  // Array out of bounds should yield UNKNOWN
+  clang_analyzer_eval(ppi[2]);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(ppi[-1]); // expected-warning{{UNKNOWN}}
+
+  return 0;
+}
+
+int testNonlocConcreteInts() {
+  static_assert(sizeof(char) == 1, "test assumes sizeof(char) is 1");
+  static_assert(sizeof(short) == 2, "test assumes sizeof(short) is 2");
+  static_assert(sizeof(int) == 4, "test assumes sizeof(int) is 4");
+  static_assert(sizeof(long) == 8, "test assumes sizeof(long) is 8");
+  static_assert(sizeof(long *) == 8, "test assumes sizeof(long *) is 8");
+
+  unsigned short sh = 0x1122;
+  unsigned char *pbsh = (unsigned char *)
+
+  unsigned int i = 0x11223344;
+  unsigned char *pbi = (unsigned char *)
+  unsigned short *psi = (unsigned short *)
+
+  unsigned 

[PATCH] D93600: [clangd] When querying drivers by binary, look in PATH too

2020-12-20 Thread Giulio Girardi via Phabricator via cfe-commits
rapgenic added a comment.

Just wanted to say that this is my first patch submission to the LLVM/clangd 
project, so please call me out on any mistake!

The arc tool caught me by surprise by opening the revision before I could 
double check it, hence the rename and edits...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93600

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


[PATCH] D93600: When querying drivers by binary, look in PATH too

2020-12-20 Thread Giulio Girardi via Phabricator via cfe-commits
rapgenic created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
rapgenic requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Sometimes compile_commands.json databases are created without an
absolute path for the driver in the command field. By default the driver
name is appended to the current directory, however if no driver is found
in that location assume it was in the default PATH and try finding it
there


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93600

Files:
  clang-tools-extra/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/clangd/test/system-include-extractor.test


Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/clangd/test/system-include-extractor.test
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -3,21 +3,24 @@
 # The mock driver below is a shell script:
 # REQUIRES: shell
 
+# Create a bin directory to store the mock-driver and add it to the path
+# RUN: mkdir -p %t.dir/bin
+# RUN: export PATH=%t.dir/bin:$PATH
 # Generate a mock-driver that will print %temp_dir%/my/dir and
 # %temp_dir%/my/dir2 as include search paths.
-# RUN: echo '#!/bin/sh' >> %t.dir/my_driver.sh
-# RUN: echo '[ "$0" = "%t.dir/my_driver.sh" ] || exit' >> %t.dir/my_driver.sh
-# RUN: echo 'args="$*"' >> %t.dir/my_driver.sh
-# RUN: echo '[ -z "${args##*"-nostdinc"*}" ] || exit' >> %t.dir/my_driver.sh
-# RUN: echo '[ -z "${args##*"-isysroot=/isysroot"*}" ] || exit' >> 
%t.dir/my_driver.sh
-# RUN: echo 'echo " $* " | grep " --sysroot /my/sysroot/path " || exit' >> 
%t.dir/my_driver.sh
-# RUN: echo 'echo line to ignore >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/my_driver.sh
-# RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'printf "End of search list.\r\n" >&2' >> %t.dir/my_driver.sh
-# RUN: chmod +x %t.dir/my_driver.sh
+# RUN: echo '#!/bin/sh' >> %t.dir/bin/my_driver.sh
+# RUN: echo '[ "$0" = "%t.dir/bin/my_driver.sh" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo 'args="$*"' >> %t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"-nostdinc"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"-isysroot=/isysroot"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo 'echo " $* " | grep " --sysroot /my/sysroot/path " || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
+# RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/bin/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/bin/my_driver.sh
+# RUN: echo 'printf "End of search list.\r\n" >&2' >> %t.dir/bin/my_driver.sh
+# RUN: chmod +x %t.dir/bin/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h
 # RUN: mkdir -p %t.dir/my/dir
@@ -27,7 +30,7 @@
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. Which should add a.h and b.h into include search path.
-# RUN: echo '[{"directory": "%/t.dir", "command": "%/t.dir/my_driver.sh 
the-file.cpp -nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot", "file": 
"the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp 
-nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot", "file": 
"the-file.cpp"}]' > %t.dir/compile_commands.json
 
 # RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
 # On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -334,6 +334,16 @@
 llvm::SmallString<128> Driver(Cmd->CommandLine.front());
 llvm::sys::fs::make_absolute(Cmd->Directory, Driver);
 
+if (!llvm::sys::fs::exists(Driver)) {
+  auto DriverProgram =
+  llvm::sys::findProgramByName(Cmd->CommandLine.front());
+  if (DriverProgram) {
+log("System include extraction: driver {0} expanded to {1}",
+Cmd->CommandLine.front(), *DriverProgram);
+Driver = *DriverProgram;
+  }
+}
+
 if (auto Info =
 QueriedDrivers.get(/*Key=*/(Driver + ":" + Lang).str(), [&] {
   return extractSystemIncludesAndTarget(


Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- 

[PATCH] D86844: [LoopDeletion] Allows deletion of possibly infinite side-effect free loops

2020-12-20 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D86844#2465027 , @jdoerfert wrote:

> @nikic Is this OK or do you want it split?

After looking again, I assume this can't really be split, because prior to this 
change we would never delete a loop without an exit block, so the code was not 
reachable before. So this looks fine to me.




Comment at: llvm/lib/Transforms/Utils/LoopUtils.cpp:621
   }
 }
 

Unrelated, but why do these updates happen before the branch from preheader to 
exit is added in IR? Shouldn't it be the other way around according to the DTU 
contract?



Comment at: llvm/lib/Transforms/Utils/LoopUtils.cpp:661
+  }
+}
   }

jdoerfert wrote:
> atmnpatel wrote:
> > nikic wrote:
> > > These fixes look unrelated. Is it possible to test them separately?
> > So my understanding is that the actual line that fixes the compile time 
> > error is 651, that is, just having that line fixes the compile time error. 
> > I would assume its because before I didn't tell the dominator tree to 
> > remove the edge connecting the preheader and header, and not having that 
> > cascade, GVN was unable to iterate properly in some cases over the (now) 
> > dead blocks because it wasn't updated in LLVM's internal structures. The 
> > actual error was from the iteration in GVN::assignValNumForDeadCode() where 
> > it would try to iterate through a block that partially existed but didn't 
> > really.
> > 
> > The lines 652-660 that update MemorySSA I added because in the other more 
> > general case above, we seem to update MemorySSA right after updating the 
> > Dominator Tree.
> Nit: Move DTU into the conditional
You might also move this code after the if/else, as it's the same in both 
branches. As the update strategy is eager, reusing the same DTU object 
shouldn't make a difference. (Feel free to leave as is though.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86844

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


[PATCH] D86844: [LoopDeletion] Allows deletion of possibly infinite side-effect free loops

2020-12-20 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

@nikic Is this OK or do you want it split?




Comment at: llvm/lib/Transforms/Utils/LoopUtils.cpp:661
+  }
+}
   }

atmnpatel wrote:
> nikic wrote:
> > These fixes look unrelated. Is it possible to test them separately?
> So my understanding is that the actual line that fixes the compile time error 
> is 651, that is, just having that line fixes the compile time error. I would 
> assume its because before I didn't tell the dominator tree to remove the edge 
> connecting the preheader and header, and not having that cascade, GVN was 
> unable to iterate properly in some cases over the (now) dead blocks because 
> it wasn't updated in LLVM's internal structures. The actual error was from 
> the iteration in GVN::assignValNumForDeadCode() where it would try to iterate 
> through a block that partially existed but didn't really.
> 
> The lines 652-660 that update MemorySSA I added because in the other more 
> general case above, we seem to update MemorySSA right after updating the 
> Dominator Tree.
Nit: Move DTU into the conditional


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86844

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


[PATCH] D88394: [Driver][M68k] (Patch 8/8) Add driver support for M68k

2020-12-20 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2089
+  static const char *const M68kTriples[] = {
+  "m68k-linux-gnu", "m68k-unknown-linux-gnu", "m68k-suse-linux"};
+

rengolin wrote:
> The front-end supports FreeBSD, too.
Aren't these arrays only used on multiarch systems so irrelevant for BSDs? 
There aren't FreeBSD triples listed for X86/X86_64 for example.


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

https://reviews.llvm.org/D88394

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


[PATCH] D88393: [cfe][M68k] (Patch 7/8) Basic Clang support

2020-12-20 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/lib/Basic/Targets/M68k.cpp:38-50
+  // M68k pointers are always 32 bit wide even for 16 bit cpus
+  Layout += "-p:32:32";
+
+  // M68k integer data types
+  Layout += "-i8:8:8-i16:16:16-i32:32:32";
+
+  // FIXME no floats at the moment

If we're in SysV psABI land, then the stack is 32-bit aligned.

If we're in actual ABI used by everyone out there, i.e. GCC's default, then 
it's only 16-bit aligned, and your integer types also have the wrong alignment, 
so you will get ABI incompatibility with GCC-built binaries as provided by 
distributions like Debian.



Comment at: clang/lib/Basic/Targets/M68k.cpp:63
+.Case("generic", CK_68000)
+.Case("M68000", CK_68000)
+.Case("M68010", CK_68010)

GCC's -mcpu excludes any M prefix and is just the number.



Comment at: clang/lib/Basic/Targets/M68k.cpp:77-79
+  Builder.defineMacro("M68k");
+  Builder.defineMacro("__M68k__");
+  Builder.defineMacro("__M68K__");

Where are these coming from? GCC only defines `__m68k__`.


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

https://reviews.llvm.org/D88393

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


[PATCH] D93597: [X86][SSE] Enable constexpr on some basic SSE intrinsics (RFC)

2020-12-20 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

  constexpr bool test() {
  float A = 1,0;
  float B = 2,0;
  float C = 3.0;
  float D = 4,0;
  __m128 AV;
  __m128 BV;
  __m128 result =  _mm_setr_ps(A, B, C, D);
  result =  _mm_setzero_ps();
  result = _mm_xor_ps(AV, BV);
  return true;
  }

It should help you to test, whether you can call all functions in constant 
evaluation contexts and normal evaluations. I don't know  whether you want to 
sprinkle some asserts into the test function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93597

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


[PATCH] D93597: [X86][SSE] Enable constexpr on some basic SSE intrinsics (RFC)

2020-12-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

In D93597#2464870 , @tschuett wrote:

> libcxx uses a function test and calls test() and static_assert(test()), see 
> below
> https://github.com/llvm/llvm-project/blob/d86a00d8febd0138a21f92d1420c4b62d7acb0ca/libcxx/test/std/utilities/memory/pointer.conversion/to_address.pass.cpp#L102-126

@tschuett could you explain a little more about how you see this working for 
vectors? Are you suggesting we embed the vector ops into static_assert ? The 
problem we have is how to extract a result from a comparison. I did wonder 
about bitcasting to a struct of some thing, but am not sure what would be best.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93597

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


[PATCH] D77598: Integral template argument suffix and cast printing

2020-12-20 Thread Pratyush Das via Phabricator via cfe-commits
reikdas marked 22 inline comments as done.
reikdas added inline comments.



Comment at: clang/lib/AST/TemplateBase.cpp:111-115
+  Out << "u8'" << Val << "'";
+else if (T->isUnsignedIntegerType() && T->isChar16Type())
+  Out << "u16'" << Val << "'";
+else if (T->isUnsignedIntegerType() && T->isChar32Type())
+  Out << "u32'" << Val << "'";

rsmith wrote:
> This isn't correct: `u8'x'` will print as `u8'120'`. Perhaps you can factor 
> code to do this properly out of `StmtPrinter::VisitCharacterLiteral`.
> 
> Also, the prefix for `char16_t` literals is `u`, not `u16`, and the prefix 
> for `char32_t` literals is `U`, not `u32`.
> This isn't correct: `u8'x'` will print as `u8'120'`. Perhaps you can factor 
> code to do this properly out of `StmtPrinter::VisitCharacterLiteral`.

I partially addressed this comment. I wasn't able to find a suitable example to 
test `u8'x'` being printed as `u8'120'`. @rsmith could you please help me by 
showing me a reproducer?




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

https://reviews.llvm.org/D77598

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


[PATCH] D93597: [X86][SSE] Enable constexpr on some basic SSE intrinsics (RFC)

2020-12-20 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

libcxx uses a function test and calls test() and static_assert(test()), see 
below
https://github.com/llvm/llvm-project/blob/d86a00d8febd0138a21f92d1420c4b62d7acb0ca/libcxx/test/std/utilities/memory/pointer.conversion/to_address.pass.cpp#L102-126


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93597

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


[PATCH] D77598: Integral template argument suffix and cast printing

2020-12-20 Thread Pratyush Das via Phabricator via cfe-commits
reikdas updated this revision to Diff 312980.
reikdas added a comment.

Address @rsmith comments.


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

https://reviews.llvm.org/D77598

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/StmtDataCollectors.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTTypeTraits.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/NestedNameSpecifier.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Analysis/PathDiagnostic.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/Analysis/eval-predefined-exprs.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p12.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p13.cpp
  clang/test/SemaCXX/builtin-align-cxx.cpp
  clang/test/SemaCXX/cxx11-ast-print.cpp
  clang/test/SemaCXX/cxx1z-ast-print.cpp
  clang/test/SemaCXX/matrix-type-builtins.cpp
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/test/SemaTemplate/delegating-constructors.cpp
  clang/test/SemaTemplate/matrix-type.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp
  clang/tools/libclang/CIndex.cpp
  
clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp

Index: clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
===
--- clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
@@ -20,7 +20,7 @@
 llvm::raw_string_ostream Stream(ArgStr);
 const TemplateArgument  = ArgLoc.getArgument();
 
-Arg.print(Context->getPrintingPolicy(), Stream);
+Arg.print(Context->getPrintingPolicy(), Stream, /*IncludeType*/ true);
 Match(Stream.str(), ArgLoc.getLocation());
 return ExpectedLocationVisitor::
   TraverseTemplateArgumentLoc(ArgLoc);
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5150,8 +5150,9 @@
 SmallString<128> Str;
 llvm::raw_svector_ostream OS(Str);
 OS << *ClassSpec;
-printTemplateArgumentList(OS, ClassSpec->getTemplateArgs().asArray(),
-  Policy);
+printTemplateArgumentList(
+OS, ClassSpec->getTemplateArgs().asArray(), Policy,
+ClassSpec->getSpecializedTemplate()->getTemplateParameters());
 return cxstring::createDup(OS.str());
   }
 
Index: clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx17.cpp
@@ -511,3 +511,33 @@
   // Ensure that we can instantiate the definition of S<...>.
   int n = *v.q + *w.q;
 }
+
+namespace TypeSuffix {
+  template  struct A {};
+  template <> struct A<1> { using type = int; }; // expected-note {{'A<1>::type' declared here}}
+  A<1L>::type a; // expected-error {{no type named 'type' in 'TypeSuffix::A<1L>'; did you mean 'A<1>::type'?}}
+
+  template  struct B {};
+  template <> struct B<1> { using type = int; }; // expected-note {{'B<1>::type' declared here}}
+  B<2>::type b;  // expected-error {{no type named 'type' in 'TypeSuffix::B<2>'; did you mean 'B<1>::type'?}}
+
+  template  struct C {};
+  template <> struct C<'a'> { using type = signed char; }; // expected-note {{'C<'a'>::type' declared here}}
+  C<(signed char)'a'>::type c; // expected-error {{no type named 'type' in 'TypeSuffix::C<(signed char)'a'>'; did you mean 'C<'a'>::type'?}}
+
+  template  struct D {};
+  template <> struct D<'a'> { using type = signed char; }; // expected-note {{'D<'a'>::type' declared here}}
+  D<'b'>::type d;  // expected-error {{no type named 'type' in 'TypeSuffix::D<'b'>'; did you mean 'D<'a'>::type'?}}
+
+  template  struct E {};
+  template <> struct E<'a'> { using type = unsigned char; }; // expected-note {{'E<'a'>::type' declared here}}
+  E<(unsigned char)'a'>::type e; // expected-error {{no type named 'type' in 'TypeSuffix::E<(unsigned char)'a'>'; did you mean 'E<'a'>::type'?}}
+
+  template  struct F {};
+  template <> struct F<'a'> { using type = unsigned char; }; // expected-note {{'F<'a'>::type' declared here}}
+  F<'b'>::type f;// expected-error {{no 

[PATCH] D93597: [X86][SSE] Enable constexpr on some basic SSE intrinsics (RFC)

2020-12-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon updated this revision to Diff 312979.
RKSimon added a comment.

missing newline


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93597

Files:
  clang/lib/Headers/xmmintrin.h
  clang/test/CodeGen/X86/sse-builtins.c

Index: clang/test/CodeGen/X86/sse-builtins.c
===
--- clang/test/CodeGen/X86/sse-builtins.c
+++ clang/test/CodeGen/X86/sse-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
-// RUN: %clang_cc1 -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
-
+// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -x c -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include 
 
@@ -807,3 +808,54 @@
   // CHECK: xor <4 x i32>
   return _mm_xor_ps(A, B);
 }
+
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+constexpr __m128 test_constexpr_mm_add_ps(__m128 A, __m128 B) {
+  return _mm_add_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_and_ps(__m128 A, __m128 B) {
+  return _mm_and_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_div_ps(__m128 A, __m128 B) {
+  return _mm_div_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_mul_ps(__m128 A, __m128 B) {
+  return _mm_mul_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_or_ps(__m128 A, __m128 B) {
+  return _mm_or_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_set_ss(float A) {
+  return _mm_set_ss(A);
+}
+
+constexpr __m128 test_constexpr_mm_set1_ps(float A) {
+  return _mm_set1_ps(A);
+}
+
+constexpr __m128 test_constexpr_mm_set_ps1(float A) {
+  return _mm_set_ps1(A);
+}
+
+constexpr __m128 test_constexpr_mm_set_ps(float A, float B, float C, float D) {
+  return _mm_set_ps(A, B, C, D);
+}
+
+constexpr __m128 test_constexpr_mm_setr_ps(float A, float B, float C, float D) {
+  return _mm_setr_ps(A, B, C, D);
+}
+
+constexpr __m128 test_constexpr_mm_setzero_ps() {
+  return _mm_setzero_ps();
+}
+
+constexpr __m128 test_constexpr_mm_xor_ps(__m128 A, __m128 B) {
+  return _mm_xor_ps(A, B);
+}
+#endif
Index: clang/lib/Headers/xmmintrin.h
===
--- clang/lib/Headers/xmmintrin.h
+++ clang/lib/Headers/xmmintrin.h
@@ -31,6 +31,12 @@
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse"), __min_vector_width__(128)))
 #define __DEFAULT_FN_ATTRS_MMX __attribute__((__always_inline__, __nodebug__, __target__("mmx,sse"), __min_vector_width__(64)))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+#endif
+
 /// Adds the 32-bit float values in the low-order bits of the operands.
 ///
 /// \headerfile 
@@ -66,7 +72,7 @@
 ///A 128-bit vector of [4 x float] containing one of the source operands.
 /// \returns A 128-bit vector of [4 x float] containing the sums of both
 ///operands.
-static __inline__ __m128 __DEFAULT_FN_ATTRS
+static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_add_ps(__m128 __a, __m128 __b)
 {
   return (__m128)((__v4sf)__a + (__v4sf)__b);
@@ -109,7 +115,7 @@
 ///A 128-bit vector of [4 x float] containing the subtrahend.
 /// \returns A 128-bit vector of [4 x float] containing the differences between
 ///both operands.
-static __inline__ __m128 __DEFAULT_FN_ATTRS
+static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_sub_ps(__m128 __a, __m128 __b)
 {
   return (__m128)((__v4sf)__a - (__v4sf)__b);
@@ -151,7 +157,7 @@
 ///A 128-bit vector of [4 x float] containing one of the source operands.
 /// \returns A 128-bit vector of [4 x float] containing the products of both
 ///operands.
-static __inline__ __m128 __DEFAULT_FN_ATTRS
+static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_mul_ps(__m128 __a, __m128 __b)
 {
   return (__m128)((__v4sf)__a * (__v4sf)__b);
@@ -192,7 +198,7 @@
 ///A 128-bit vector of [4 x float] containing the divisor.
 /// \returns A 128-bit vector of [4 x float] 

[PATCH] D93597: [X86][SSE] Enable constexpr on some basic SSE intrinsics (RFC)

2020-12-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.
RKSimon added reviewers: craig.topper, pengfei, rsmith, erichkeane, spatel.
RKSimon requested review of this revision.
Herald added a project: clang.

This is an initial exploratory patch towards making some (basic initialization 
and arithmetic) SSE/AVX intrinsics usable in constant expressions.

I've only touched the SSE1 intrinsics that we can do so far - if people are 
happy with the approach I'll extend the patch to cover the equivalent 
SSE2->AVX512 intrinsics/types.

My main concern is how best to test these - all we're doing so far is checking 
that they will compile, which might be enough for now?

A later patch will have to address how to support 
__builtin_shufflevector/__builtin_convertvector and element accessors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93597

Files:
  clang/lib/Headers/xmmintrin.h
  clang/test/CodeGen/X86/sse-builtins.c

Index: clang/test/CodeGen/X86/sse-builtins.c
===
--- clang/test/CodeGen/X86/sse-builtins.c
+++ clang/test/CodeGen/X86/sse-builtins.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
-// RUN: %clang_cc1 -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
-
+// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -x c -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include 
 
@@ -807,3 +808,54 @@
   // CHECK: xor <4 x i32>
   return _mm_xor_ps(A, B);
 }
+
+// Test constexpr handling.
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+constexpr __m128 test_constexpr_mm_add_ps(__m128 A, __m128 B) {
+  return _mm_add_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_and_ps(__m128 A, __m128 B) {
+  return _mm_and_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_div_ps(__m128 A, __m128 B) {
+  return _mm_div_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_mul_ps(__m128 A, __m128 B) {
+  return _mm_mul_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_or_ps(__m128 A, __m128 B) {
+  return _mm_or_ps(A, B);
+}
+
+constexpr __m128 test_constexpr_mm_set_ss(float A) {
+  return _mm_set_ss(A);
+}
+
+constexpr __m128 test_constexpr_mm_set1_ps(float A) {
+  return _mm_set1_ps(A);
+}
+
+constexpr __m128 test_constexpr_mm_set_ps1(float A) {
+  return _mm_set_ps1(A);
+}
+
+constexpr __m128 test_constexpr_mm_set_ps(float A, float B, float C, float D) {
+  return _mm_set_ps(A, B, C, D);
+}
+
+constexpr __m128 test_constexpr_mm_setr_ps(float A, float B, float C, float D) {
+  return _mm_setr_ps(A, B, C, D);
+}
+
+constexpr __m128 test_constexpr_mm_setzero_ps() {
+  return _mm_setzero_ps();
+}
+
+constexpr __m128 test_constexpr_mm_xor_ps(__m128 A, __m128 B) {
+  return _mm_xor_ps(A, B);
+}
+#endif
\ No newline at end of file
Index: clang/lib/Headers/xmmintrin.h
===
--- clang/lib/Headers/xmmintrin.h
+++ clang/lib/Headers/xmmintrin.h
@@ -31,6 +31,12 @@
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse"), __min_vector_width__(128)))
 #define __DEFAULT_FN_ATTRS_MMX __attribute__((__always_inline__, __nodebug__, __target__("mmx,sse"), __min_vector_width__(64)))
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
+#else
+#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
+#endif
+
 /// Adds the 32-bit float values in the low-order bits of the operands.
 ///
 /// \headerfile 
@@ -66,7 +72,7 @@
 ///A 128-bit vector of [4 x float] containing one of the source operands.
 /// \returns A 128-bit vector of [4 x float] containing the sums of both
 ///operands.
-static __inline__ __m128 __DEFAULT_FN_ATTRS
+static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR
 _mm_add_ps(__m128 __a, __m128 __b)
 {
   return (__m128)((__v4sf)__a + (__v4sf)__b);
@@ -109,7 +115,7 @@
 ///A 128-bit vector of [4 x float] containing the subtrahend.
 /// \returns A 128-bit vector of [4 x float] containing the differences between
 ///both operands.
-static __inline__ __m128 __DEFAULT_FN_ATTRS
+static 

[PATCH] D93595: [analyzer] Fix extraction of punned and known SVals

2020-12-20 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

This proposed change seems to address the referenced issues 
(https://bugs.llvm.org/show_bug.cgi?id=39032 and 
https://bugs.llvm.org/show_bug.cgi?id=44114). I believe the scalars test cases 
to be mostly complete, and the structures test cases to be at most a baseline 
(just based on covering specific cases mentioned in the bug reports). Please 
let me know how to improve through review comments and I'll work on that. 
Thanks to Balazs, Gabor, Artem and Denis for feedback in the email thread and 
help working through this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93595

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


[PATCH] D93595: [analyzer] Prototype change to fix type punning of known SVals

2020-12-20 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 312977.
vabridgers added a comment.

Update commit header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93595

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/concrete-endian.cpp
  clang/test/Analysis/punning-structures.cpp

Index: clang/test/Analysis/punning-structures.cpp
===
--- /dev/null
+++ clang/test/Analysis/punning-structures.cpp
@@ -0,0 +1,161 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-unknown-linux-gnu -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple powerpc64-unknown-linux-gnu  -verify %s
+
+void clang_analyzer_dump(int);
+void clang_analyzer_eval(int);
+
+int printf(const char *__restrict, ...);
+
+typedef unsigned int uint32_t;
+typedef __typeof(sizeof(int)) size_t;
+
+// case-38931-1
+typedef struct {
+  unsigned short var;
+} A;
+
+typedef struct {
+  unsigned short var;
+} B;
+
+typedef struct {
+  unsigned long var;
+} C;
+
+typedef struct {
+  long a, b;
+} X;
+
+void fn(char);
+
+extern int foo(char);
+
+// Cases to cover reproducer in https://bugs.llvm.org/show_bug.cgi?id=43364.
+// Still TODO!!!
+int blah(A *param, int *x) {
+  if (param->var != 0)// reg_$1}->RetCode>
+return ((B *)param)->var; // reg_$2{element{B, 0 S32b, SymRegion{reg_$0}->RetCore}
+  *x = 1;
+  return 0;
+}
+
+int foo(A *param) {
+  int x;
+  if (blah(param, ) != 0) {
+return 0;
+  }
+  // FIXME!! Should be no warning!! https://bugs.llvm.org/show_bug.cgi?id=43364
+  return x; // expected-warning{{}} false positive: "returning garbage value".
+}
+
+int fee(int *a) {
+  int *b = a;
+  clang_analyzer_eval(*b == *a); // expected-warning{{TRUE}}
+  return 0;
+}
+
+int foonew(A *s1) {
+  // s1->code = 0; // uncomment this to see the case pass.
+  B *s2 = (B *)s1;
+
+  // FIXME!! Should be TRUE. https://bugs.llvm.org/show_bug.cgi?id=43364
+  //clang_analyzer_eval(s2->var == s1->var); // e xpected-warning{{TRUE}}
+  //clang_analyzer_dump(s1->RetCode); // reg_$2}.code>
+  //clang_analyzer_dump(s2->RetCode); // reg_$1},0 S64b,B}.code>
+  return 0;
+}
+
+// Derivative reproducer for case https://bugs.llvm.org/show_bug.cgi?id=39032
+int structpunning(void) {
+  A localvar = {0x1122};
+
+  char *p = (char *)
+  int x = 0;
+  if (p[0])
+x += 1;
+  if (p[1]) // Branch condition evaluates to a garbage value [core.uninitialized.Branch]
+x += 1;
+  return x;
+}
+
+// Derivative reproducer for case https://bugs.llvm.org/show_bug.cgi?id=39032
+int case15982(void) {
+  unsigned long myVar1 = 654321UL;
+  char *p1 = (char *)
+  foo(p1[0]);
+  foo(p1[1]);
+
+  C myVar2 = {654321UL};
+  char *p2 = (char *)
+  foo(p2[0]);
+  foo(p2[1]);
+
+  C myVar3 = {654321UL};
+  char *p3 = (char *)
+  foo(p3[0]);
+  foo(p3[1]);
+
+  return 0;
+}
+
+// Case to cover reproducer in https://bugs.llvm.org/show_bug.cgi?id=39032
+void fn2() {
+  X str = {0, 0};
+  char *ptr = (char *)
+  fn(ptr[1]);
+}
+
+void fn3() {
+  long long xx = 0;
+  char *ptr = (char *)
+  fn(ptr[200]);
+}
+
+// Case to cover reproducer in https://bugs.llvm.org/show_bug.cgi?id=44114
+struct device_registers {
+  uint32_t n1;
+  uint32_t n2;
+  uint32_t n3;
+  uint32_t n4;
+  uint32_t n5;
+} __attribute__((packed));
+
+static_assert(20 == sizeof(struct device_registers), "unexpected struct size");
+
+static void CopyDeviceRegisters(
+struct device_registers volatile ,
+struct device_registers volatile *src) {
+  dest.n1 = src->n1;
+  dest.n2 = src->n2;
+  dest.n3 = src->n3;
+  dest.n4 = src->n4;
+  dest.n5 = src->n5;
+}
+
+// this is a pretend process_bytes() from boost/crc.hpp
+// (where it's a member function)
+void process_bytes(void const *buffer, size_t byte_count) {
+  // "checksum creation"
+  unsigned char const *const b = static_cast(buffer);
+  for (size_t i = 0; i < byte_count; i++) {
+printf("%02X ", b[i]);
+  }
+  printf("\n");
+}
+
+int case44114() {
+  // in our code this is a uio mapping
+  struct device_registers mock {};
+  struct device_registers volatile *mapped_regs = 
+
+  // purpose is to get a copy of the volatile mapping to compute a
+  // checksum
+  struct device_registers shadow;
+
+  CopyDeviceRegisters(shadow, mapped_regs);
+
+  // now we merely need to read from the (shadow) struct to mimick
+  // what the real process_bytes() would do ...
+  process_bytes(, sizeof(shadow));
+  return 0;
+}
Index: clang/test/Analysis/concrete-endian.cpp
===
--- /dev/null
+++ clang/test/Analysis/concrete-endian.cpp
@@ -0,0 +1,201 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-unknown-linux-gnu -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple powerpc64-unknown-linux-gnu  -verify %s
+

[PATCH] D93586: [InstCombine] use poison as placeholder for undemanded elems

2020-12-20 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added reviewers: nlopes, regehr, RKSimon, zhengyangl, nikic, hfinkel.
spatel added a comment.

Thank you for working on this! Looking back at the bug comments (and adding 
reviewers based on those comments), this is a step towards killing undef that 
has been discussed for a long time now. :)

Besides changing IRBuilder and shufflevector's definition, I think we'll also 
need updates in the vectorizers, InstSimplify, and other places in InstCombine 
that use UndefValue for InsertElement and shuffle transforms.

> A conservative way is copying all tests having insertelement undef & 
> replacing it with insertelement poison & run Alive2 on it, but it will create 
> many tests and people won’t like it. :(

Do you have an estimate of how many tests are out there? If it's a temporary 
increase and not huge, I don't think there is much downside. But if we think 
the transition will take a long time, then maybe we don't want the duplication.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93586

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


[PATCH] D93595: [analyzer] Prototype change to fix type punning of known SVals

2020-12-20 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 312976.
vabridgers added a comment.

Clean up a few typos


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93595

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/concrete-endian.cpp
  clang/test/Analysis/punning-structures.cpp

Index: clang/test/Analysis/punning-structures.cpp
===
--- /dev/null
+++ clang/test/Analysis/punning-structures.cpp
@@ -0,0 +1,161 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-unknown-linux-gnu -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple powerpc64-unknown-linux-gnu  -verify %s
+
+void clang_analyzer_dump(int);
+void clang_analyzer_eval(int);
+
+int printf(const char *__restrict, ...);
+
+typedef unsigned int uint32_t;
+typedef __typeof(sizeof(int)) size_t;
+
+// case-38931-1
+typedef struct {
+  unsigned short var;
+} A;
+
+typedef struct {
+  unsigned short var;
+} B;
+
+typedef struct {
+  unsigned long var;
+} C;
+
+typedef struct {
+  long a, b;
+} X;
+
+void fn(char);
+
+extern int foo(char);
+
+// Cases to cover reproducer in https://bugs.llvm.org/show_bug.cgi?id=43364.
+// Still TODO!!!
+int blah(A *param, int *x) {
+  if (param->var != 0)// reg_$1}->RetCode>
+return ((B *)param)->var; // reg_$2{element{B, 0 S32b, SymRegion{reg_$0}->RetCore}
+  *x = 1;
+  return 0;
+}
+
+int foo(A *param) {
+  int x;
+  if (blah(param, ) != 0) {
+return 0;
+  }
+  // FIXME!! Should be no warning!! https://bugs.llvm.org/show_bug.cgi?id=43364
+  return x; // expected-warning{{}} false positive: "returning garbage value".
+}
+
+int fee(int *a) {
+  int *b = a;
+  clang_analyzer_eval(*b == *a); // expected-warning{{TRUE}}
+  return 0;
+}
+
+int foonew(A *s1) {
+  // s1->code = 0; // uncomment this to see the case pass.
+  B *s2 = (B *)s1;
+
+  // FIXME!! Should be TRUE. https://bugs.llvm.org/show_bug.cgi?id=43364
+  //clang_analyzer_eval(s2->var == s1->var); // e xpected-warning{{TRUE}}
+  //clang_analyzer_dump(s1->RetCode); // reg_$2}.code>
+  //clang_analyzer_dump(s2->RetCode); // reg_$1},0 S64b,B}.code>
+  return 0;
+}
+
+// Derivative reproducer for case https://bugs.llvm.org/show_bug.cgi?id=39032
+int structpunning(void) {
+  A localvar = {0x1122};
+
+  char *p = (char *)
+  int x = 0;
+  if (p[0])
+x += 1;
+  if (p[1]) // Branch condition evaluates to a garbage value [core.uninitialized.Branch]
+x += 1;
+  return x;
+}
+
+// Derivative reproducer for case https://bugs.llvm.org/show_bug.cgi?id=39032
+int case15982(void) {
+  unsigned long myVar1 = 654321UL;
+  char *p1 = (char *)
+  foo(p1[0]);
+  foo(p1[1]);
+
+  C myVar2 = {654321UL};
+  char *p2 = (char *)
+  foo(p2[0]);
+  foo(p2[1]);
+
+  C myVar3 = {654321UL};
+  char *p3 = (char *)
+  foo(p3[0]);
+  foo(p3[1]);
+
+  return 0;
+}
+
+// Case to cover reproducer in https://bugs.llvm.org/show_bug.cgi?id=39032
+void fn2() {
+  X str = {0, 0};
+  char *ptr = (char *)
+  fn(ptr[1]);
+}
+
+void fn3() {
+  long long xx = 0;
+  char *ptr = (char *)
+  fn(ptr[200]);
+}
+
+// Case to cover reproducer in https://bugs.llvm.org/show_bug.cgi?id=44114
+struct device_registers {
+  uint32_t n1;
+  uint32_t n2;
+  uint32_t n3;
+  uint32_t n4;
+  uint32_t n5;
+} __attribute__((packed));
+
+static_assert(20 == sizeof(struct device_registers), "unexpected struct size");
+
+static void CopyDeviceRegisters(
+struct device_registers volatile ,
+struct device_registers volatile *src) {
+  dest.n1 = src->n1;
+  dest.n2 = src->n2;
+  dest.n3 = src->n3;
+  dest.n4 = src->n4;
+  dest.n5 = src->n5;
+}
+
+// this is a pretend process_bytes() from boost/crc.hpp
+// (where it's a member function)
+void process_bytes(void const *buffer, size_t byte_count) {
+  // "checksum creation"
+  unsigned char const *const b = static_cast(buffer);
+  for (size_t i = 0; i < byte_count; i++) {
+printf("%02X ", b[i]);
+  }
+  printf("\n");
+}
+
+int case44114() {
+  // in our code this is a uio mapping
+  struct device_registers mock {};
+  struct device_registers volatile *mapped_regs = 
+
+  // purpose is to get a copy of the volatile mapping to compute a
+  // checksum
+  struct device_registers shadow;
+
+  CopyDeviceRegisters(shadow, mapped_regs);
+
+  // now we merely need to read from the (shadow) struct to mimick
+  // what the real process_bytes() would do ...
+  process_bytes(, sizeof(shadow));
+  return 0;
+}
Index: clang/test/Analysis/concrete-endian.cpp
===
--- /dev/null
+++ clang/test/Analysis/concrete-endian.cpp
@@ -0,0 +1,201 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-unknown-linux-gnu -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple powerpc64-unknown-linux-gnu  -verify %s
+

[PATCH] D93596: [ASTMatchers] Traverse-ignore range-for implementation details

2020-12-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93596

Files:
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2580,6 +2580,31 @@
 EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
 EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
   }
+  {
+auto M = binaryOperator(hasOperatorName("!="));
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = unaryOperator(hasOperatorName("++"));
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = declStmt(hasSingleDecl(varDecl(matchesName("__range";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = declStmt(hasSingleDecl(varDecl(matchesName("__begin";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = declStmt(hasSingleDecl(varDecl(matchesName("__end";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
 
   Code = R"cpp(
   void rangeFor()
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -413,6 +413,22 @@
   // The following Visit*() and Traverse*() functions "override"
   // methods in RecursiveASTVisitor.
 
+  bool TraverseCXXForRangeStmt(CXXForRangeStmt *S,
+   DataRecursionQueue *Queue = nullptr) {
+if (!WalkUpFromCXXForRangeStmt(S))
+  return false;
+for (Stmt *SubStmt : getStmtChildren(S)) {
+  if (SubStmt == S->getInit() || SubStmt == S->getLoopVarStmt() ||
+  SubStmt == S->getRangeInit() || SubStmt == S->getBody()) {
+TraverseStmt(SubStmt, Queue);
+  } else {
+ASTNodeNotSpelledInSourceScope RAII(this, true);
+TraverseStmt(SubStmt, Queue);
+  }
+}
+return true;
+  }
+
   bool VisitTypedefNameDecl(TypedefNameDecl *DeclNode) {
 // When we see 'typedef A B', we add name 'B' to the set of names
 // A's canonical type maps to.  This is necessary for implementing


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2580,6 +2580,31 @@
 EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
 EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
   }
+  {
+auto M = binaryOperator(hasOperatorName("!="));
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = unaryOperator(hasOperatorName("++"));
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = declStmt(hasSingleDecl(varDecl(matchesName("__range";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = declStmt(hasSingleDecl(varDecl(matchesName("__begin";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
+  {
+auto M = declStmt(hasSingleDecl(varDecl(matchesName("__end";
+EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+  }
 
   Code = R"cpp(
   void rangeFor()
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -413,6 +413,22 @@
   // The following Visit*() and Traverse*() functions "override"
   // methods in RecursiveASTVisitor.
 
+  bool TraverseCXXForRangeStmt(CXXForRangeStmt *S,
+   DataRecursionQueue *Queue = nullptr) {
+if (!WalkUpFromCXXForRangeStmt(S))
+  return false;
+for (Stmt 

[PATCH] D93452: [clangd] Trim memory periodically

2020-12-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Sorry to mess you around like this, but I think I might have jumped the gun in 
asking this to be abstracted away in `Process.h`. My reasoning is:

- Once we are injecting the cleanup function from ClangdMain, that's not 
actually a crazy place to put this kind of system-level code, behind #ifdefs
- The abstraction costs us something: we can't skip all the locking etc for 
memory cleanups if it's a no-op on our platform
- We're putting an abstraction around one implementation without any reason to 
believe other implementations need this treatment or can use a similar 
interface. This is likely to turn out to be a poor abstraction, and 
llvm/Support isn't the easiest place to iterate on it.

So I think my favorite option may be back to:

- Have ClangdLSPServer::Options take a nullable `std::function` to 
abstract the (optional) platform-specific operation
- Have ClangdMain contain platform #ifdefs and define+inject the wrapper that 
calls `malloc_trim`
- Optionally: have a clangd or cmake flag to disable this even if glibc was 
detected. This provides a workaround for other allocators if we need it.

Again, I'm sorry if it seems we're going in circles. I might put together a 
patch for this variant to compare...

In D93452#2464643 , @njames93 wrote:

> Just attached a debugger and ran malloc_trim on my clangd instance which was 
> sitting at 6.7GB, afterwards it was 1.3GB. Interestingly clangd held rock 
> solid at 1.0GB recorded memory usage throughout.

Great to have confirmation of this, thanks!
Clangd's own memory-usage staying constant is expected (it's counting the live 
objects), as is real usage being higher (we count a subset, and we don't count 
malloc overhead/fragmentation).

In D93452#2464764 , @qchateau wrote:

>> Interestingly clangd held rock solid at 1.0GB recorded memory usage 
>> throughout.
>
> What do you mean exactly ? Using the built in memory usage measurement ?

Yeah pretty sure this is the `$/memoryUsage` request or equivalent.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:52
+// Malloc trim minimal period
+std::chrono::seconds MemoryCleanupPeriod = std::chrono::seconds(60);
 

qchateau wrote:
> sammccall wrote:
> > I don't particularly think the interval needs to be set through options 
> > (memory profiling interval isn't), we can just hardcode this.
> > 
> > On the other hand, doing this at all should be optional, and I think we 
> > should enable it from ClangdMain - this is a weird thing for a library to 
> > be doing by default, and as it stands we'll be doing it in unit tests and 
> > stuff.
> > 
> > I think my favorite variant would be
> > ```
> > /// If set, periodically called to release memory.
> > /// Consider llvm::sys::Process::ReleaseHeapMemory;
> > std::function MemoryCleanup = nullptr;
> > ```
> Sounds good, do you think [1] we should throttle the calls to `MemoryCleanup` 
> or [2] throttle the calls to `malloc_trim` from within the callback ?
> 
> >I don't particularly think the interval needs to be set through options 
> >(memory profiling interval isn't), we can just hardcode this.
> >
> >On the other hand, doing this at all should be optional, and I think we 
> >should enable it from ClangdMain - this is a weird thing for a library to be 
> >doing by default, and as it stands we'll be doing it in unit tests and stuff.
> 
> I like the idea of configuring the `MemoryCleanup` function from ClangdMain, 
> but it's as easy to have [3] an int option that configures the interval as it 
> is to have [4] a boolean one to just disable it.
> 
> I actually think both points are related:
> - If we choose [2], then I'd go for [3] because it is more configurable and 
> adds no code complexity.
> - If we choose [1], then I agree we can go for [4] to avoid an extra option
> Sounds good, do you think [1] we should throttle the calls to MemoryCleanup 
> or [2] throttle the calls to malloc_trim from within the callback ?

I think ClangdLSPServer should throttle the calls to the callback, because 
exactly what events trigger it internally is an implementation detail, and 
triggering periodically is a more useful API.

> I like the idea of configuring the MemoryCleanup function from ClangdMain, 
> but it's as easy to have [3] an int option that configures the interval as it 
> is to have [4] a boolean one to just disable it.

If you configure the callback as a`std::function`, then it has a null state 
that naturally means "don't clean up memory", so you don't need the boolean. In 
this context I'm not sure having an option to configure is worthwhile.



Comment at: llvm/cmake/config-ix.cmake:235
 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
+check_symbol_exists(malloc_trim malloc.h HAVE_MALLOC_TRIM)
 check_symbol_exists(malloc_zone_statistics malloc/malloc.h

For clangd's purposes 

[PATCH] D93595: [analyzer] Prototype change to fix type punning of known SVals

2020-12-20 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
Herald added subscribers: steakhal, ASDenysPetrov, martong, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun, whisperity.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change addresses the specific cases described in these cases,
addresses another related escaped defect and adds covering LITs.

  https://bugs.llvm.org/show_bug.cgi?id=43364
  https://bugs.llvm.org/show_bug.cgi?id=44114

This patch was co-authored with Balazs Benics (steakhal), and debug
assistance from Gabor Marton (martong).

Region store is taught to recognize punned concrete integers and extract
the data in an endianess correct way for scalars and structures. The
escaped defect was incorrect data extracted for big endian targets under
analysis in a particular case.

Co-authored-by: Balazs Benics 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93595

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/concrete-endian.cpp
  clang/test/Analysis/punning-structures.cpp

Index: clang/test/Analysis/punning-structures.cpp
===
--- /dev/null
+++ clang/test/Analysis/punning-structures.cpp
@@ -0,0 +1,162 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-unknown-linux-gnu -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple powerpc64-unknown-linux-gnu  -verify %s
+
+void clang_analyzer_dump(int);
+void clang_analyzer_eval(int);
+
+int printf(const char *__restrict, ...);
+
+typedef unsigned int uint32_t;
+typedef __typeof(sizeof(int)) size_t;
+
+// case-38931-1
+typedef struct {
+  unsigned short var;
+} A;
+
+typedef struct {
+  unsigned short var;
+} B;
+
+typedef struct {
+  unsigned long var;
+} C;
+
+typedef struct {
+  long a, b;
+} X;
+
+void fn(char);
+
+extern int foo(char);
+
+// Cases to cover reproducer in https://bugs.llvm.org/show_bug.cgi?id=43364.
+// Still TODO!!!
+int blah(A *param, int *x) {
+  if (param->var != 0)// reg_$1}->RetCode>
+return ((B *)param)->var; // reg_$2{element{B, 0 S32b, SymRegion{reg_$0}->RetCore}
+  *x = 1;
+  return 0;
+}
+
+int foo(A *param) {
+  int x;
+  if (blah(param, ) != 0) {
+return 0;
+  }
+  // FIXME!! Should be no warning!! https://bugs.llvm.org/show_bug.cgi?id=43364
+  return x; // expected-warning{{}} false positive: "returning garbage value".
+}
+
+// case-38931-2
+int fee(int *a) {
+  int *b = a;
+  clang_analyzer_eval(*b == *a); // expected-warning{{TRUE}}
+  return 0;
+}
+
+int foonew(A *s1) {
+  // s1->code = 0; // uncomment this to see the case pass.
+  B *s2 = (B *)s1;
+
+  // FIXME!! Should be TRUE. https://bugs.llvm.org/show_bug.cgi?id=43364
+  //clang_analyzer_eval(s2->var == s1->var); // e xpected-warning{{TRUE}}
+  //clang_analyzer_dump(s1->RetCode); // reg_$2}.code>
+  //clang_analyzer_dump(s2->RetCode); // reg_$1},0 S64b,B}.code>
+  return 0;
+}
+
+// Derivative reproducer for case https://bugs.llvm.org/show_bug.cgi?id=39032
+int structpunning(void) {
+  A localvar = {0x1122};
+
+  char *p = (char *)
+  int x = 0;
+  if (p[0])
+x += 1;
+  if (p[1]) // Branch condition evaluates to a garbage value [core.uninitialized.Branch]
+x += 1;
+  return x;
+}
+
+// Derivative reproducer for case https://bugs.llvm.org/show_bug.cgi?id=39032
+int case15982(void) {
+  unsigned long myVar1 = 654321UL;
+  char *p1 = (char *)
+  foo(p1[0]);
+  foo(p1[1]);
+
+  C myVar2 = {654321UL};
+  char *p2 = (char *)
+  foo(p2[0]);
+  foo(p2[1]);
+
+  C myVar3 = {654321UL};
+  char *p3 = (char *)
+  foo(p3[0]);
+  foo(p3[1]);
+
+  return 0;
+}
+
+// Case to cover reproducer in https://bugs.llvm.org/show_bug.cgi?id=39032
+void fn2() {
+  X str = {0, 0};
+  char *ptr = (char *)
+  fn(ptr[1]);
+}
+
+void fn3() {
+  long long xx = 0;
+  char *ptr = (char *)
+  fn(ptr[200]);
+}
+
+// Case to cover reproducer in https://bugs.llvm.org/show_bug.cgi?id=44114
+struct device_registers {
+  uint32_t n1;
+  uint32_t n2;
+  uint32_t n3;
+  uint32_t n4;
+  uint32_t n5;
+} __attribute__((packed));
+
+static_assert(20 == sizeof(struct device_registers), "unexpected struct size");
+
+static void CopyDeviceRegisters(
+struct device_registers volatile ,
+struct device_registers volatile *src) {
+  dest.n1 = src->n1;
+  dest.n2 = src->n2;
+  dest.n3 = src->n3;
+  dest.n4 = src->n4;
+  dest.n5 = src->n5;
+}
+
+// this is a pretend process_bytes() from boost/crc.hpp
+// (where it's a member function)
+void process_bytes(void const *buffer, size_t byte_count) {
+  // "checksum creation"
+  unsigned char const *const b = static_cast(buffer);
+  for (size_t i = 0; i < byte_count; i++) {
+printf("%02X ", b[i]);
+  }
+  printf("\n");
+}
+
+int case44114() {
+  // in our code this is a uio mapping
+  struct device_registers mock {};
+  struct 

[PATCH] D93452: [clangd] Trim memory periodically

2020-12-20 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau added a comment.

> Interestingly clangd held rock solid at 1.0GB recorded memory usage 
> throughout.

What do you mean exactly ? Using the built in memory usage measurement ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93452

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


[clang] 7e84aa1 - Fix MSVC "not all control paths return a value" warnings. NFCI.

2020-12-20 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-12-20T11:32:40Z
New Revision: 7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0

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

LOG: Fix MSVC "not all control paths return a value" warnings. NFCI.

Add missing llvm_unreachable()'s after each all-enums switch statement.

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 74a31c0a1b65..9d31a8701241 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -7637,6 +7637,7 @@ static Expr 
*BuildExpressionFromNonTypeTemplateArgumentValue(
 auto *OVE = new (S.Context) OpaqueValueExpr(Loc, T, VK);
 return ConstantExpr::Create(S.Context, OVE, Val);
   }
+  llvm_unreachable("Unhandled APValue::ValueKind enum");
 }
 
 ExprResult
@@ -7666,6 +7667,7 @@ Sema::BuildExpressionFromNonTypeTemplateArgument(const 
TemplateArgument ,
 return BuildExpressionFromNonTypeTemplateArgumentValue(
 *this, Arg.getUncommonValueType(), Arg.getAsUncommonValue(), Loc);
   }
+  llvm_unreachable("Unhandled TemplateArgument::ArgKind enum");
 }
 
 /// Match two template parameters within template parameter lists.



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


[PATCH] D93333: [clang-tidy] ppcoreguidelines-pro-type-member-init: suppress warning for default member funcs

2020-12-20 Thread Malcolm Parsons via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG35f2c3a8b41f: [clang-tidy] 
cppcoreguidelines-pro-type-member-init: suppress warning for… (authored by 
cwarner-8702, committed by malcolm.parsons).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D9

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -501,3 +501,19 @@
 void Bug33557() {
   NegativeImplicitInheritedCtor I(5);
 }
+
+struct NegativeDefaultedCtorOutOfDecl {
+  NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &);
+  int F;
+};
+
+NegativeDefaultedCtorOutOfDecl::NegativeDefaultedCtorOutOfDecl(const 
NegativeDefaultedCtorOutOfDecl &) = default;
+
+struct PositiveDefaultConstructorOutOfDecl {
+  PositiveDefaultConstructorOutOfDecl();
+  int F;
+  // CHECK-FIXES: int F{};
+};
+
+PositiveDefaultConstructorOutOfDecl::PositiveDefaultConstructorOutOfDecl() = 
default;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: F
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -297,6 +297,10 @@
 // Skip declarations delayed by late template parsing without a body.
 if (!Ctor->getBody())
   return;
+// Skip out-of-band explicitly defaulted special member functions
+// (except the default constructor).
+if (Ctor->isExplicitlyDefaulted() && !Ctor->isDefaultConstructor())
+  return;
 checkMissingMemberInitializer(*Result.Context, *Ctor->getParent(), Ctor);
 checkMissingBaseClassInitializer(*Result.Context, *Ctor->getParent(), 
Ctor);
   } else if (const auto *Record =


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -501,3 +501,19 @@
 void Bug33557() {
   NegativeImplicitInheritedCtor I(5);
 }
+
+struct NegativeDefaultedCtorOutOfDecl {
+  NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &);
+  int F;
+};
+
+NegativeDefaultedCtorOutOfDecl::NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &) = default;
+
+struct PositiveDefaultConstructorOutOfDecl {
+  PositiveDefaultConstructorOutOfDecl();
+  int F;
+  // CHECK-FIXES: int F{};
+};
+
+PositiveDefaultConstructorOutOfDecl::PositiveDefaultConstructorOutOfDecl() = default;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -297,6 +297,10 @@
 // Skip declarations delayed by late template parsing without a body.
 if (!Ctor->getBody())
   return;
+// Skip out-of-band explicitly defaulted special member functions
+// (except the default constructor).
+if (Ctor->isExplicitlyDefaulted() && !Ctor->isDefaultConstructor())
+  return;
 checkMissingMemberInitializer(*Result.Context, *Ctor->getParent(), Ctor);
 checkMissingBaseClassInitializer(*Result.Context, *Ctor->getParent(), Ctor);
   } else if (const auto *Record =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 35f2c3a - [clang-tidy] cppcoreguidelines-pro-type-member-init: suppress warning for default member funcs

2020-12-20 Thread Malcolm Parsons via cfe-commits

Author: Chris Warner
Date: 2020-12-20T11:22:41Z
New Revision: 35f2c3a8b41fd3b6ef88d013a7c3ed9478b765e4

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

LOG: [clang-tidy] cppcoreguidelines-pro-type-member-init: suppress warning for 
default member funcs

Modify the cppcoreguidelines-pro-type-member-init checker to ignore warnings 
from the move and copy-constructors when they are compiler defined with `= 
default` outside of the type declaration.

Reported as [LLVM bug 36819](https://bugs.llvm.org/show_bug.cgi?id=36819)

Reviewed By: malcolm.parsons

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index a223d215af1b..67856be843e7 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -297,6 +297,10 @@ void ProTypeMemberInitCheck::check(const 
MatchFinder::MatchResult ) {
 // Skip declarations delayed by late template parsing without a body.
 if (!Ctor->getBody())
   return;
+// Skip out-of-band explicitly defaulted special member functions
+// (except the default constructor).
+if (Ctor->isExplicitlyDefaulted() && !Ctor->isDefaultConstructor())
+  return;
 checkMissingMemberInitializer(*Result.Context, *Ctor->getParent(), Ctor);
 checkMissingBaseClassInitializer(*Result.Context, *Ctor->getParent(), 
Ctor);
   } else if (const auto *Record =

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
index 28230dd6952e..403f28baf99d 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -501,3 +501,19 @@ struct NegativeImplicitInheritedCtor : 
NegativeImplicitInheritedCtorBase {
 void Bug33557() {
   NegativeImplicitInheritedCtor I(5);
 }
+
+struct NegativeDefaultedCtorOutOfDecl {
+  NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &);
+  int F;
+};
+
+NegativeDefaultedCtorOutOfDecl::NegativeDefaultedCtorOutOfDecl(const 
NegativeDefaultedCtorOutOfDecl &) = default;
+
+struct PositiveDefaultConstructorOutOfDecl {
+  PositiveDefaultConstructorOutOfDecl();
+  int F;
+  // CHECK-FIXES: int F{};
+};
+
+PositiveDefaultConstructorOutOfDecl::PositiveDefaultConstructorOutOfDecl() = 
default;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize 
these fields: F



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