[PATCH] D29221: clang-format-vsix: "format on save" feature

2017-02-26 Thread Antonio Maiorano via Phabricator via cfe-commits
amaiorano updated this revision to Diff 89815.
amaiorano added a comment.

Made changes based on @hans 's feedback.

I looked again at the categories, and I think it makes sense with my changes. 
Here's an updated screenshot that shows what the options menu in Visual Studio 
looks like with these changes with the top-level category name ("LLVM/Clang") 
and page name ("Clang Format") highlighted, as well as the category names for 
the page items ("Format Options" and "Format On Save") highlighted:

F3117958: pasted_file 

It would be nice if "Format On Save" was _below_ "Format Options", but Visual 
Studio always orders the page categories in alphabetical order, so this is 
pretty standard.


https://reviews.llvm.org/D29221

Files:
  tools/clang-format-vs/ClangFormat/ClangFormat.csproj
  tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
  tools/clang-format-vs/ClangFormat/RunningDocTableEventsDispatcher.cs
  tools/clang-format-vs/ClangFormat/Vsix.cs

Index: tools/clang-format-vs/ClangFormat/Vsix.cs
===
--- /dev/null
+++ tools/clang-format-vs/ClangFormat/Vsix.cs
@@ -0,0 +1,96 @@
+using EnvDTE;
+using Microsoft.VisualStudio.Editor;
+using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Shell.Interop;
+using Microsoft.VisualStudio.Text;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.TextManager.Interop;
+using System;
+using System.IO;
+
+namespace LLVM.ClangFormat
+{
+internal sealed class Vsix
+{
+/// 
+/// Returns the currently active view if it is a IWpfTextView.
+/// 
+public static IWpfTextView GetCurrentView()
+{
+// The SVsTextManager is a service through which we can get the active view.
+var textManager = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));
+IVsTextView textView;
+textManager.GetActiveView(1, null, out textView);
+
+// Now we have the active view as IVsTextView, but the text interfaces we need
+// are in the IWpfTextView.
+return VsToWpfTextView(textView);
+}
+
+public static bool IsDocumentDirty(Document document)
+{
+var textView = GetDocumentView(document);
+var textDocument = GetTextDocument(textView);
+return textDocument?.IsDirty == true;
+}
+
+public static IWpfTextView GetDocumentView(Document document)
+{
+var textView = GetVsTextViewFrompPath(document.FullName);
+return VsToWpfTextView(textView);
+}
+
+public static IWpfTextView VsToWpfTextView(IVsTextView textView)
+{
+var userData = (IVsUserData)textView;
+if (userData == null)
+return null;
+Guid guidWpfViewHost = DefGuidList.guidIWpfTextViewHost;
+object host;
+userData.GetData(ref guidWpfViewHost, out host);
+return ((IWpfTextViewHost)host).TextView;
+}
+
+public static IVsTextView GetVsTextViewFrompPath(string filePath)
+{
+// From http://stackoverflow.com/a/2427368/4039972
+var dte2 = (EnvDTE80.DTE2)Package.GetGlobalService(typeof(SDTE));
+var sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte2;
+var serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(sp);
+
+IVsUIHierarchy uiHierarchy;
+uint itemID;
+IVsWindowFrame windowFrame;
+if (VsShellUtilities.IsDocumentOpen(serviceProvider, filePath, Guid.Empty,
+out uiHierarchy, out itemID, out windowFrame))
+{
+// Get the IVsTextView from the windowFrame.
+return VsShellUtilities.GetTextView(windowFrame);
+}
+return null;
+}
+
+public static ITextDocument GetTextDocument(IWpfTextView view)
+{
+ITextDocument document;
+if (view != null && view.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document))
+return document;
+return null;
+}
+
+public static string GetDocumentParent(IWpfTextView view)
+{
+ITextDocument document = GetTextDocument(view);
+if (document != null)
+{
+return Directory.GetParent(document.FilePath).ToString();
+}
+return null;
+}
+
+public static string GetDocumentPath(IWpfTextView view)
+{
+return GetTextDocument(view)?.FilePath;
+}
+}
+}
Index: tools/clang-format-vs/ClangFormat/RunningDocTableEventsDispatcher.cs
===
--- /dev/null
+++ tools/clang-format-vs/ClangFormat/RunningDocTableEventsDispatcher.cs
@@ -0,0 +1,79 @@
+using EnvD

r296296 - [X86] DAZ Macros Relocation

2017-02-26 Thread Oren Ben Simhon via cfe-commits
Author: orenb
Date: Sun Feb 26 05:58:15 2017
New Revision: 296296

URL: http://llvm.org/viewvc/llvm-project?rev=296296&view=rev
Log:
[X86] DAZ Macros Relocation

The DAZ feature introduces the denormal zero support for x86.
Currently the definitions are located under SSE3 header, however there are some 
SSE2 targets that support the feature as well.

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


Modified:
cfe/trunk/lib/Headers/emmintrin.h
cfe/trunk/lib/Headers/pmmintrin.h

Modified: cfe/trunk/lib/Headers/emmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/emmintrin.h?rev=296296&r1=296295&r2=296296&view=diff
==
--- cfe/trunk/lib/Headers/emmintrin.h (original)
+++ cfe/trunk/lib/Headers/emmintrin.h Sun Feb 26 05:58:15 2017
@@ -4810,4 +4810,12 @@ void _mm_pause(void);
 
 #define _MM_SHUFFLE2(x, y) (((x) << 1) | (y))
 
+#define _MM_DENORMALS_ZERO_ON   (0x0040)
+#define _MM_DENORMALS_ZERO_OFF  (0x)
+
+#define _MM_DENORMALS_ZERO_MASK (0x0040)
+
+#define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK)
+#define _MM_SET_DENORMALS_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & 
~_MM_DENORMALS_ZERO_MASK) | (x)))
+
 #endif /* __EMMINTRIN_H */

Modified: cfe/trunk/lib/Headers/pmmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/pmmintrin.h?rev=296296&r1=296295&r2=296296&view=diff
==
--- cfe/trunk/lib/Headers/pmmintrin.h (original)
+++ cfe/trunk/lib/Headers/pmmintrin.h Sun Feb 26 05:58:15 2017
@@ -257,14 +257,6 @@ _mm_movedup_pd(__m128d __a)
   return __builtin_shufflevector((__v2df)__a, (__v2df)__a, 0, 0);
 }
 
-#define _MM_DENORMALS_ZERO_ON   (0x0040)
-#define _MM_DENORMALS_ZERO_OFF  (0x)
-
-#define _MM_DENORMALS_ZERO_MASK (0x0040)
-
-#define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK)
-#define _MM_SET_DENORMALS_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & 
~_MM_DENORMALS_ZERO_MASK) | (x)))
-
 /// \brief Establishes a linear address memory range to be monitored and puts
 ///the processor in the monitor event pending state. Data stored in the
 ///monitored address range causes the processor to exit the pending state.


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


Re: r296296 - [X86] DAZ Macros Relocation

2017-02-26 Thread Craig Topper via cfe-commits
Doesn't Intel's own documentation say these are in pmmintrin.h?  gcc has
them there as well.

https://software.intel.com/en-us/node/683881

~Craig

On Sun, Feb 26, 2017 at 3:58 AM, Oren Ben Simhon via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: orenb
> Date: Sun Feb 26 05:58:15 2017
> New Revision: 296296
>
> URL: http://llvm.org/viewvc/llvm-project?rev=296296&view=rev
> Log:
> [X86] DAZ Macros Relocation
>
> The DAZ feature introduces the denormal zero support for x86.
> Currently the definitions are located under SSE3 header, however there are
> some SSE2 targets that support the feature as well.
>
> Differential Revision: https://reviews.llvm.org/D30194
>
>
> Modified:
> cfe/trunk/lib/Headers/emmintrin.h
> cfe/trunk/lib/Headers/pmmintrin.h
>
> Modified: cfe/trunk/lib/Headers/emmintrin.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/
> emmintrin.h?rev=296296&r1=296295&r2=296296&view=diff
> 
> ==
> --- cfe/trunk/lib/Headers/emmintrin.h (original)
> +++ cfe/trunk/lib/Headers/emmintrin.h Sun Feb 26 05:58:15 2017
> @@ -4810,4 +4810,12 @@ void _mm_pause(void);
>
>  #define _MM_SHUFFLE2(x, y) (((x) << 1) | (y))
>
> +#define _MM_DENORMALS_ZERO_ON   (0x0040)
> +#define _MM_DENORMALS_ZERO_OFF  (0x)
> +
> +#define _MM_DENORMALS_ZERO_MASK (0x0040)
> +
> +#define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() &
> _MM_DENORMALS_ZERO_MASK)
> +#define _MM_SET_DENORMALS_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() &
> ~_MM_DENORMALS_ZERO_MASK) | (x)))
> +
>  #endif /* __EMMINTRIN_H */
>
> Modified: cfe/trunk/lib/Headers/pmmintrin.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/
> pmmintrin.h?rev=296296&r1=296295&r2=296296&view=diff
> 
> ==
> --- cfe/trunk/lib/Headers/pmmintrin.h (original)
> +++ cfe/trunk/lib/Headers/pmmintrin.h Sun Feb 26 05:58:15 2017
> @@ -257,14 +257,6 @@ _mm_movedup_pd(__m128d __a)
>return __builtin_shufflevector((__v2df)__a, (__v2df)__a, 0, 0);
>  }
>
> -#define _MM_DENORMALS_ZERO_ON   (0x0040)
> -#define _MM_DENORMALS_ZERO_OFF  (0x)
> -
> -#define _MM_DENORMALS_ZERO_MASK (0x0040)
> -
> -#define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() &
> _MM_DENORMALS_ZERO_MASK)
> -#define _MM_SET_DENORMALS_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() &
> ~_MM_DENORMALS_ZERO_MASK) | (x)))
> -
>  /// \brief Establishes a linear address memory range to be monitored and
> puts
>  ///the processor in the monitor event pending state. Data stored in
> the
>  ///monitored address range causes the processor to exit the pending
> state.
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30372: [Driver] Consolidate tools and toolchains by target platform. (NFC)

2017-02-26 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Have you considered using "include_directories" in CMakeLists.txt to avoid 
including "../Something.h"?


https://reviews.llvm.org/D30372



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


[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-02-26 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 89817.
madsravn marked an inline comment as done.
madsravn added a comment.

Made small changes based on comments.


https://reviews.llvm.org/D30158

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tidy/modernize/ReplaceRandomShuffleCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
  test/clang-tidy/modernize-replace-random-shuffle.cpp

Index: test/clang-tidy/modernize-replace-random-shuffle.cpp
===
--- test/clang-tidy/modernize-replace-random-shuffle.cpp
+++ test/clang-tidy/modernize-replace-random-shuffle.cpp
@@ -0,0 +1,58 @@
+// RUN: %check_clang_tidy %s modernize-replace-random-shuffle %t -- -- -std=c++11
+
+//CHECK-FIXES: #include 
+
+namespace std {
+template  struct vec_iterator {
+  T *ptr;
+  vec_iterator operator++(int);
+};
+
+template  struct vector {
+  typedef vec_iterator iterator;
+
+  iterator begin();
+  iterator end();
+};
+
+template 
+void random_shuffle(FwIt begin, FwIt end);
+
+template 
+void random_shuffle(FwIt begin, FwIt end, randomFunc& randomfunc);
+
+template 
+void shuffle(FwIt begin, FwIt end);
+} // namespace std
+
+// Random Func
+int myrandom (int i) { return i;}
+
+using namespace std;
+
+int main() {
+  std::vector vec;
+
+  std::random_shuffle(vec.begin(), vec.end());
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: do not use 'random_shuffle'. It is deprecated and replaced by 'shuffle'
+  // CHECK-FIXES: std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+
+  std::shuffle(vec.begin(), vec.end());
+
+  random_shuffle(vec.begin(), vec.end());
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: do not use 'random_shuffle'. It is deprecated and replaced by 'shuffle'
+  // CHECK-FIXES: shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+  
+  std::random_shuffle(vec.begin(), vec.end(), myrandom);
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: do not use 'random_shuffle'. It is deprecated and replaced by 'shuffle'. The old user defined 'RandomFunction' is not usable for shuffle. You need to make additional changes if you want a specific random function
+  // CHECK-FIXES: std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+  random_shuffle(vec.begin(), vec.end(), myrandom);
+  // CHECK-MESSAGE: [[@LINE-1]]:3: warning: do not use 'random_shuffle'. It is deprecated and replaced by 'shuffle'. The old user defined 'RandomFunction' is not usable for shuffle. You need to make additional changes if you want a specific random function
+  // CHECK-FIXES: shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+  shuffle(vec.begin(), vec.end());
+
+  return 0;
+}
Index: docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
===
--- docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
+++ docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
@@ -0,0 +1,28 @@
+.. title:: clang-tidy - modernize-replace-random-shuffle
+
+modernize-replace-random-shuffle
+
+
+This check will find occurrences of ``std::random_shuffle`` and replace it with ``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available and thus we need to replace it.
+
+Below is two examples of what kind of occurrences will be found and two examples of what it will be replaced with.
+
+.. code-block:: c++
+
+  std::vector v;
+
+  // First example
+  std::random_shuffle(vec.begin(), vec.end());
+
+  // Second example
+  std::random_shuffle(vec.begin(), vec.end(), randomFun);
+
+Both these examples will be replaced with
+
+.. code-block:: c++
+
+  std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+
+The second example will also receive a warning that ``randomFunc`` is no longer supported in the same way as before so if the user wants the same functionality, the user will need to change the implementation of the ``randomFunc``.
+
+One thing to be aware of here is that ``std::random_device`` is quite expensive to initialize. So if you are using the code in a performance critical place, you probably want to initialize it elsewhere. 
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -110,6 +110,7 @@
modernize-raw-string-literal
modernize-redundant-void-arg
modernize-replace-auto-ptr
+   modernize-replace-random-shuffle
modernize-return-braced-init-list
modernize-shrink-to-fit
modernize-use-auto
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -72,6 +72,11 @@
 
   Find

[PATCH] D27455: UBSan docs: Explicitly mention that `-fsanitize=unsigned-integer-overflow` does not catch UB.

2017-02-26 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

samsonov: ping


https://reviews.llvm.org/D27455



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


[PATCH] D30385: clang-format: Don't leave behind temp files in -i mode on Windows, PR26125, reloaded

2017-02-26 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
Herald added a subscriber: klimek.

Second attempt after http://llvm.org/viewvc/llvm-project?rev=296166&view=rev

In the first attempt, `Code` (the memory buffer backing the input file) was 
reset before `overwriteChangedFiles()` was called, but 
`overwriteChangedFiles()` still reads from it.  Now, give 
`overwriteChangedFiles()` a callback that's called after the input's been read 
but before the output's written, and then call `Code.reset()` from that 
callback.

(Since the test is identical to what was in the repo before chapuni's revert, 
`svn diff` doesn't show it – see the above link for the test.)


https://reviews.llvm.org/D30385

Files:
  include/clang/Rewrite/Core/Rewriter.h
  lib/Frontend/Rewrite/FixItRewriter.cpp
  lib/Rewrite/Rewriter.cpp
  lib/Tooling/Refactoring.cpp
  test/Format/inplace.cpp
  tools/clang-format/ClangFormat.cpp
  unittests/Tooling/RefactoringTest.cpp
  unittests/Tooling/RewriterTest.cpp

Index: tools/clang-format/ClangFormat.cpp
===
--- tools/clang-format/ClangFormat.cpp
+++ tools/clang-format/ClangFormat.cpp
@@ -299,7 +299,10 @@
 if (Inplace) {
   if (FileName == "-")
 errs() << "error: cannot use -i when reading from stdin.\n";
-  else if (Rewrite.overwriteChangedFiles())
+  else if (Rewrite.overwriteChangedFiles([&Code, ID](FileID FID) {
+ assert(FID == ID);
+ Code.reset();
+   }))
 return true;
 } else {
   if (Cursor.getNumOccurrences() != 0)
Index: lib/Tooling/Refactoring.cpp
===
--- lib/Tooling/Refactoring.cpp
+++ lib/Tooling/Refactoring.cpp
@@ -64,7 +64,9 @@
 }
 
 int RefactoringTool::saveRewrittenFiles(Rewriter &Rewrite) {
-  return Rewrite.overwriteChangedFiles() ? 1 : 0;
+  // FIXME: This likely leaks temp files on Windows, see comment on
+  // Rewriter::overwriteChangedFiles().
+  return Rewrite.overwriteChangedFiles([](FileID){}) ? 1 : 0;
 }
 
 bool formatAndApplyAllReplacements(
Index: lib/Frontend/Rewrite/FixItRewriter.cpp
===
--- lib/Frontend/Rewrite/FixItRewriter.cpp
+++ lib/Frontend/Rewrite/FixItRewriter.cpp
@@ -82,9 +82,9 @@
   Editor.applyRewrites(Rec);
 
   if (FixItOpts->InPlace) {
-// Overwriting open files on Windows is tricky, but the rewriter can do it
-// for us.
-Rewrite.overwriteChangedFiles();
+// FIXME: This likely leaks temp files on Windows, see comment on
+// Rewriter::overwriteChangedFiles().
+Rewrite.overwriteChangedFiles([](FileID){});
 return false;
   }
 
Index: lib/Rewrite/Rewriter.cpp
===
--- lib/Rewrite/Rewriter.cpp
+++ lib/Rewrite/Rewriter.cpp
@@ -443,15 +443,16 @@
 };
 } // end anonymous namespace
 
-bool Rewriter::overwriteChangedFiles() {
+bool Rewriter::overwriteChangedFiles(llvm::function_ref prewrite) {
   bool AllWritten = true;
   for (buffer_iterator I = buffer_begin(), E = buffer_end(); I != E; ++I) {
 const FileEntry *Entry =
 getSourceMgr().getFileEntryForID(I->first);
 AtomicallyMovedFile File(getSourceMgr().getDiagnostics(), Entry->getName(),
  AllWritten);
 if (File.ok()) {
   I->second.write(File.getStream());
+  prewrite(I->first);
 }
   }
   return !AllWritten;
Index: include/clang/Rewrite/Core/Rewriter.h
===
--- include/clang/Rewrite/Core/Rewriter.h
+++ include/clang/Rewrite/Core/Rewriter.h
@@ -184,7 +184,18 @@
   /// Returns true if any files were not saved successfully.
   /// Outputs diagnostics via the source manager's diagnostic engine
   /// in case of an error.
-  bool overwriteChangedFiles();
+  ///
+  /// prewrite(FID) is called after all changes to FID have been written to a
+  /// temporary file, but before that temporary file is moved into FID's
+  /// location.  Windows's ReplaceFileW(to, from) internally creates (another)
+  /// temporary file and swaps the data streams of that file with the one of
+  /// |to| so that it's possible to replace an opened file.  However, if |to|
+  /// _was_ opened, the temp file now has that open data stream, and
+  /// ReplaceFileW() fails to delete it, causing a tempo file leak.  To fix,
+  /// clients of this function must close all file mappings of a file before
+  /// it's written to (but after it's been read by Rewriter), and this prewrite
+  /// callback is a convenient place for doing this.
+  bool overwriteChangedFiles(llvm::function_ref prewrite);
 
 private:
   unsigned getLocationOffsetAndFileID(SourceLocation Loc, FileID &FID) const;
Index: unittests/Tooling/RewriterTest.cpp
===
--- unittests/Tooling/RewriterTest.cpp
+++ unittests/Tooling/RewriterTest.cpp
@@ -19,7 +19,9 @@
   Rewri

[PATCH] D30385: clang-format: Don't leave behind temp files in -i mode on Windows, PR26125, reloaded

2017-02-26 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

(related, and why i picked rnk as reviewer: 
https://bugs.llvm.org/show_bug.cgi?id=17216 
https://bugs.llvm.org/show_bug.cgi?id=17960)


https://reviews.llvm.org/D30385



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


[PATCH] D28348: [analyzer] Taught the analyzer about Glib API to check Memory-leak

2017-02-26 Thread Leslie Zhai via Phabricator via cfe-commits
xiangzhai updated this revision to Diff 89825.
xiangzhai added a comment.

Hi Anna,

Thanks for your review!

I updated the Glib-MallocChecker-single-size-value.patch to use **zeroVal** for 
**g_malloc0** and **g_try_malloc0**

and Yes, I refer CallocMem to implement **SValBinMulOp** in the 
Glib-MallocChecker-all-in-one.patch 
 if this 
patch could be submitted to UPSTREAM, then I create another patch for XXX_n, 
thanks for your suggest!

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D28348

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  test/Analysis/gmalloc.c

Index: test/Analysis/gmalloc.c
===
--- test/Analysis/gmalloc.c
+++ test/Analysis/gmalloc.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store=region -verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+typedef void* gpointer;
+typedef const void* gconstpointer;
+typedef unsigned long gsize;
+typedef unsigned int guint;
+
+gpointer g_malloc(gsize n_bytes);
+gpointer g_malloc0(gsize n_bytes);
+gpointer g_realloc(gpointer mem, gsize n_bytes);
+gpointer g_try_malloc(gsize n_bytes);
+gpointer g_try_malloc0(gsize n_bytes);
+gpointer g_try_realloc(gpointer mem, gsize n_bytes);
+void g_free(gpointer mem);
+gpointer g_memdup(gconstpointer mem, guint byte_size);
+
+static const gsize n_bytes = 1024;
+
+void f1() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g2); // expected-warning{{Attempt to free released memory}}
+}
+
+void f2() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2);
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g3);
+  g3 = g_memdup(g3, n_bytes); // expected-warning{{Use of memory after it is freed}}
+}
+
+void f3() {
+  gpointer g1 = g_malloc(n_bytes);
+  gpointer g2 = g_malloc0(n_bytes);
+  g1 = g_realloc(g1, n_bytes * 2);
+  gpointer g3 = g_try_malloc(n_bytes);
+  gpointer g4 = g_try_malloc0(n_bytes);
+  g3 = g_try_realloc(g3, n_bytes * 2); // expected-warning{{Potential leak of memory pointed to by 'g4'}}
+
+  g_free(g1);
+  g_free(g2);
+  g_free(g3);
+}
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -174,7 +174,10 @@
 II_valloc(nullptr), II_reallocf(nullptr), II_strndup(nullptr),
 II_strdup(nullptr), II_win_strdup(nullptr), II_kmalloc(nullptr),
 II_if_nameindex(nullptr), II_if_freenameindex(nullptr),
-II_wcsdup(nullptr), II_win_wcsdup(nullptr) {}
+II_wcsdup(nullptr), II_win_wcsdup(nullptr), II_g_malloc(nullptr),
+II_g_malloc0(nullptr), II_g_realloc(nullptr), II_g_try_malloc(nullptr), 
+II_g_try_malloc0(nullptr), II_g_try_realloc(nullptr), 
+II_g_free(nullptr), II_g_memdup(nullptr) {}
 
   /// In pessimistic mode, the checker assumes that it does not know which
   /// functions might free the memory.
@@ -236,7 +239,9 @@
  *II_realloc, *II_calloc, *II_valloc, *II_reallocf,
  *II_strndup, *II_strdup, *II_win_strdup, *II_kmalloc,
  *II_if_nameindex, *II_if_freenameindex, *II_wcsdup,
- *II_win_wcsdup;
+ *II_win_wcsdup, *II_g_malloc, *II_g_malloc0, 
+ *II_g_realloc, *II_g_try_malloc, *II_g_try_malloc0, 
+ *II_g_try_realloc, *II_g_free, *II_g_memdup;
   mutable Optional KernelZeroFlagVal;
 
   void initIdentifierInfo(ASTContext &C) const;
@@ -554,6 +559,16 @@
   II_win_strdup = &Ctx.Idents.get("_strdup");
   II_win_wcsdup = &Ctx.Idents.get("_wcsdup");
   II_win_alloca = &Ctx.Idents.get("_alloca");
+
+  // Glib
+  II_g_malloc = &Ctx.Idents.get("g_malloc");
+  II_g_malloc0 = &Ctx.Idents.get("g_malloc0");
+  II_g_realloc = &Ctx.Idents.get("g_realloc");
+  II_g_try_malloc = &Ctx.Idents.get("g_try_malloc");
+  II_g_try_malloc0 = &Ctx.Idents.get("g_try_malloc0");
+  II_g_try_realloc = &Ctx.Idents.get("g_try_realloc");
+  II_g_free = &Ctx.Idents.get("g_free");
+  II_g_memdup = &Ctx.Idents.get("g_memdup");
 }
 
 bool MallocChecker::isMemFunction(const FunctionDecl *FD, ASTContext &C) const {
@@ -589,15 +604,20 @@
 initIdentifierInfo(C);
 
 if (Family == AF_Malloc && CheckFree) {
-  if (FunI == II_free || FunI == II_realloc || FunI == II_reallocf)
+  if (FunI == II_free || FunI == II_realloc || FunI == II_reallocf || 
+  

r296306 - Add a cc1 flag for setting the existing Preprocessor option 'AllowPCHWithCompilerErrors'.

2017-02-26 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Sun Feb 26 20:06:18 2017
New Revision: 296306

URL: http://llvm.org/viewvc/llvm-project?rev=296306&view=rev
Log:
Add a cc1 flag for setting the existing Preprocessor option 
'AllowPCHWithCompilerErrors'.

Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Index/pch-from-libclang.c

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=296306&r1=296305&r2=296306&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Sun Feb 26 20:06:18 2017
@@ -588,6 +588,8 @@ def pic_is_pie : Flag<["-"], "pic-is-pie
   HelpText<"File is for a position independent executable">;
 def fno_validate_pch : Flag<["-"], "fno-validate-pch">,
   HelpText<"Disable validation of precompiled headers">;
+def fallow_pch_with_errors : Flag<["-"], "fallow-pch-with-compiler-errors">,
+  HelpText<"Accept a PCH file that was created with compiler errors">;
 def dump_deserialized_pch_decls : Flag<["-"], "dump-deserialized-decls">,
   HelpText<"Dump declarations that are deserialized from PCH, for testing">;
 def error_on_deserialized_pch_decl : Separate<["-"], 
"error-on-deserialized-decl">,

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=296306&r1=296305&r2=296306&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sun Feb 26 20:06:18 2017
@@ -2296,6 +2296,7 @@ static void ParsePreprocessorArgs(Prepro
   Opts.UsePredefines = !Args.hasArg(OPT_undef);
   Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record);
   Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch);
+  Opts.AllowPCHWithCompilerErrors = Args.hasArg(OPT_fallow_pch_with_errors);
 
   Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls);
   for (const Arg *A : Args.filtered(OPT_error_on_deserialized_pch_decl))

Modified: cfe/trunk/test/Index/pch-from-libclang.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/pch-from-libclang.c?rev=296306&r1=296305&r2=296306&view=diff
==
--- cfe/trunk/test/Index/pch-from-libclang.c (original)
+++ cfe/trunk/test/Index/pch-from-libclang.c Sun Feb 26 20:06:18 2017
@@ -3,17 +3,19 @@
 // FIXME: Non-darwin bots fail. Would need investigation using 
-module-file-info to see what is the difference in modules generated from 
libclang vs the compiler invocation, in those systems.
 // REQUIRES: system-darwin
 
+// RUN: %clang_cc1 -fsyntax-only %s -verify
 // RUN: c-index-test -write-pch %t.h.pch %s -fmodules 
-fmodules-cache-path=%t.mcp -Xclang -triple -Xclang x86_64-apple-darwin
-// RUN: %clang -fsyntax-only -include %t.h %s -Xclang -verify -fmodules 
-fmodules-cache-path=%t.mcp -Xclang -detailed-preprocessing-record -Xclang 
-triple -Xclang x86_64-apple-darwin
-
-// expected-no-diagnostics
+// RUN: %clang -fsyntax-only -include %t.h %s -Xclang -verify -fmodules 
-fmodules-cache-path=%t.mcp -Xclang -detailed-preprocessing-record -Xclang 
-triple -Xclang x86_64-apple-darwin -Xclang -fallow-pch-with-compiler-errors
 
 #ifndef HEADER
 #define HEADER
 
 struct S { int x; };
 
+void some_function(undeclared_type p); // expected-error{{unknown type name}}
+
 #else
+// expected-no-diagnostics
 
 void test(struct S *s) {
   s->x = 0;


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


[PATCH] D30373: [analyzer] NFC: Update test infrastructure to support multiple constraint managers

2017-02-26 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


https://reviews.llvm.org/D30373



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


[PATCH] D30388: [XRay] Add -fxray-{always, never}-instrument= flags to clang

2017-02-26 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris created this revision.
Herald added subscribers: mgorny, jfb.

The -fxray-always-instrument= and -fxray-never-instrument= flags take
filenames that are used to imbue the XRay instrumentation attributes
using a whitelist mechanism (similar to the sanitizer special cases
list). We use the same syntax and semantics as the sanitizer blacklists
files in the implementation.

As implemented, we respect the attributes that are already defined in
the source file (i.e. those that have the
[[clang::xray_{always,never}_instrument]] attributes) before applying
the always/never instrument lists.


https://reviews.llvm.org/D30388

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Basic/XRayFunctionFilter.h
  include/clang/Driver/Options.td
  lib/AST/ASTContext.cpp
  lib/Basic/CMakeLists.txt
  lib/Basic/LangOptions.cpp
  lib/Basic/XRayFunctionFilter.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/xray-always-instrument.cpp

Index: test/CodeGen/xray-always-instrument.cpp
===
--- /dev/null
+++ test/CodeGen/xray-always-instrument.cpp
@@ -0,0 +1,15 @@
+// RUN: echo "fun:*foo*" > %t.always-instrument
+// RUN: echo "src:*xray-always-instrument.cpp" >> %t.always-instrument
+// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 -fxray-always-instrument=%t.always-instrument -emit-llvm -o - %s -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+void foo() {}
+
+[[clang::xray_never_instrument]] void bar() {}
+
+void baz() {}
+
+// CHECK: define void @_Z3foov() #[[ALWAYSATTR:[0-9]+]] {
+// CHECK: define void @_Z3barv() #[[NEVERATTR:[0-9]+]] {
+// CHECK: define void @_Z3bazv() #[[ALWAYSATTR:[0-9]+]] {
+// CHECK: attributes #[[ALWAYSATTR]] = {{.*}} "function-instrument"="xray-always" {{.*}}
+// CHECK: attributes #[[NEVERATTR]] = {{.*}} "function-instrument"="xray-never" {{.*}}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2281,6 +2281,14 @@
   Opts.SanitizeAddressFieldPadding =
   getLastArgIntValue(Args, OPT_fsanitize_address_field_padding, 0, Diags);
   Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist);
+
+  // -fxray-{always,never}-instrument= filenames.
+  Opts.XRayInstrument =
+  Args.hasFlag(OPT_fxray_instrument, OPT_fnoxray_instrument, false);
+  Opts.XRayAlwaysInstrumentFiles =
+  Args.getAllArgValues(OPT_fxray_always_instrument);
+  Opts.XRayNeverInstrumentFiles =
+  Args.getAllArgValues(OPT_fxray_never_instrument);
 }
 
 static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SanitizerBlacklist.h"
+#include "clang/Basic/XRayFunctionFilter.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -1126,6 +1127,12 @@
   QualType Ty,
   StringRef Category = StringRef()) const;
 
+  /// Imbue XRay attributes to a function, applying the always/never attribute
+  /// lists in the process. Returns true if we did imbue attributes this way,
+  /// false otherwise.
+  bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
+  StringRef Category = StringRef()) const;
+
   SanitizerMetadata *getSanitizerMetadata() {
 return SanitizerMD.get();
   }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1482,6 +1482,30 @@
   return false;
 }
 
+bool CodeGenModule::imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
+   StringRef Category) const {
+  if (!LangOpts.XRayInstrument)
+return false;
+  const auto &XRayFilter = getContext().getXRayFilter();
+  using ImbueAttr = XRayFunctionFilter::ImbueAttribute;
+  auto Attr = XRayFunctionFilter::ImbueAttribute::NONE;
+  if (Loc.isValid())
+Attr = XRayFilter.shouldImbueLocation(Loc, Category);
+  if (Attr == ImbueAttr::NONE)
+Attr = XRayFilter.shouldImbueFunction(Fn->getName());
+  switch (Attr) {
+  case ImbueAttr::NONE:
+return false;
+  case ImbueAttr::ALWAYS:
+Fn->addFnAttr("function-instrument", "xray-always");
+break;
+  case ImbueAttr::NEVER:
+Fn->addFnAttr("function-instrument", "xray-never");
+break;
+  }
+  return true;
+}
+
 bool CodeGenModule::MustBeEmitted(const ValueDecl *Global) {
   // Never defer when EmitAllDecls is specified.
  

[PATCH] D30388: [XRay] Add -fxray-{always, never}-instrument= flags to clang

2017-02-26 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris planned changes to this revision.
dberris added a comment.

Need to undo some unnecessary formatting changes..


https://reviews.llvm.org/D30388



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


[PATCH] D30388: [XRay] Add -fxray-{always, never}-instrument= flags to clang

2017-02-26 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris updated this revision to Diff 89830.
dberris added a comment.

- fixup: undo clang-format on ASTContext.h
- fixup: undo clang-formatting whole file
- fixup: undo clang-format on file


https://reviews.llvm.org/D30388

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Basic/XRayFunctionFilter.h
  include/clang/Driver/Options.td
  lib/AST/ASTContext.cpp
  lib/Basic/CMakeLists.txt
  lib/Basic/LangOptions.cpp
  lib/Basic/XRayFunctionFilter.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/xray-always-instrument.cpp

Index: test/CodeGen/xray-always-instrument.cpp
===
--- /dev/null
+++ test/CodeGen/xray-always-instrument.cpp
@@ -0,0 +1,15 @@
+// RUN: echo "fun:*foo*" > %t.always-instrument
+// RUN: echo "src:*xray-always-instrument.cpp" >> %t.always-instrument
+// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 -fxray-always-instrument=%t.always-instrument -emit-llvm -o - %s -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+void foo() {}
+
+[[clang::xray_never_instrument]] void bar() {}
+
+void baz() {}
+
+// CHECK: define void @_Z3foov() #[[ALWAYSATTR:[0-9]+]] {
+// CHECK: define void @_Z3barv() #[[NEVERATTR:[0-9]+]] {
+// CHECK: define void @_Z3bazv() #[[ALWAYSATTR:[0-9]+]] {
+// CHECK: attributes #[[ALWAYSATTR]] = {{.*}} "function-instrument"="xray-always" {{.*}}
+// CHECK: attributes #[[NEVERATTR]] = {{.*}} "function-instrument"="xray-never" {{.*}}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2281,6 +2281,14 @@
   Opts.SanitizeAddressFieldPadding =
   getLastArgIntValue(Args, OPT_fsanitize_address_field_padding, 0, Diags);
   Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist);
+
+  // -fxray-{always,never}-instrument= filenames.
+  Opts.XRayInstrument =
+  Args.hasFlag(OPT_fxray_instrument, OPT_fnoxray_instrument, false);
+  Opts.XRayAlwaysInstrumentFiles =
+  Args.getAllArgValues(OPT_fxray_always_instrument);
+  Opts.XRayNeverInstrumentFiles =
+  Args.getAllArgValues(OPT_fxray_never_instrument);
 }
 
 static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -28,6 +28,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SanitizerBlacklist.h"
+#include "clang/Basic/XRayFunctionFilter.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -1126,6 +1127,12 @@
   QualType Ty,
   StringRef Category = StringRef()) const;
 
+  /// Imbue XRay attributes to a function, applying the always/never attribute
+  /// lists in the process. Returns true if we did imbue attributes this way,
+  /// false otherwise.
+  bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
+  StringRef Category = StringRef()) const;
+
   SanitizerMetadata *getSanitizerMetadata() {
 return SanitizerMD.get();
   }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1482,6 +1482,30 @@
   return false;
 }
 
+bool CodeGenModule::imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
+   StringRef Category) const {
+  if (!LangOpts.XRayInstrument)
+return false;
+  const auto &XRayFilter = getContext().getXRayFilter();
+  using ImbueAttr = XRayFunctionFilter::ImbueAttribute;
+  auto Attr = XRayFunctionFilter::ImbueAttribute::NONE;
+  if (Loc.isValid())
+Attr = XRayFilter.shouldImbueLocation(Loc, Category);
+  if (Attr == ImbueAttr::NONE)
+Attr = XRayFilter.shouldImbueFunction(Fn->getName());
+  switch (Attr) {
+  case ImbueAttr::NONE:
+return false;
+  case ImbueAttr::ALWAYS:
+Fn->addFnAttr("function-instrument", "xray-always");
+break;
+  case ImbueAttr::NEVER:
+Fn->addFnAttr("function-instrument", "xray-never");
+break;
+  }
+  return true;
+}
+
 bool CodeGenModule::MustBeEmitted(const ValueDecl *Global) {
   // Never defer when EmitAllDecls is specified.
   if (LangOpts.EmitAllDecls)
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -780,9 +780,10 @@
   if (XRayAttr->neverXRayInstrument())
 Fn->addFnAttr("function-instrument", "xray-never");
 } else {
-  Fn->addFnAttr(
-  "xray-instruction-threshol

r296320 - [GeneratePCHAction] If preprocessor option 'AllowPCHWithCompilerErrors' is enabled, don't delete the produced PCH file if error diagnostics occurred.

2017-02-26 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Sun Feb 26 21:52:36 2017
New Revision: 296320

URL: http://llvm.org/viewvc/llvm-project?rev=296320&view=rev
Log:
[GeneratePCHAction] If preprocessor option 'AllowPCHWithCompilerErrors' is 
enabled, don't delete the produced PCH file if error diagnostics occurred.

Modified:
cfe/trunk/include/clang/Frontend/FrontendActions.h
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/test/Index/pch-from-libclang.c

Modified: cfe/trunk/include/clang/Frontend/FrontendActions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendActions.h?rev=296320&r1=296319&r2=296320&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendActions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendActions.h Sun Feb 26 21:52:36 2017
@@ -80,6 +80,8 @@ protected:
 
   bool hasASTFileSupport() const override { return false; }
 
+  bool shouldEraseOutputFiles() override;
+
 public:
   /// \brief Compute the AST consumer arguments that will be used to
   /// create the PCHGenerator instance returned by CreateASTConsumer.

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=296320&r1=296319&r2=296320&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Sun Feb 26 21:52:36 2017
@@ -93,7 +93,7 @@ GeneratePCHAction::CreateASTConsumer(Com
   Consumers.push_back(llvm::make_unique(
 CI.getPreprocessor(), OutputFile, Sysroot,
 Buffer, CI.getFrontendOpts().ModuleFileExtensions,
-/*AllowASTWithErrors*/false,
+  
/*AllowASTWithErrors*/CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
 /*IncludeTimestamps*/
   +CI.getFrontendOpts().IncludeTimestamps));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
@@ -127,6 +127,12 @@ GeneratePCHAction::ComputeASTConsumerArg
   return OS;
 }
 
+bool GeneratePCHAction::shouldEraseOutputFiles() {
+  if (getCompilerInstance().getPreprocessorOpts().AllowPCHWithCompilerErrors)
+return false;
+  return ASTFrontendAction::shouldEraseOutputFiles();
+}
+
 bool GeneratePCHAction::BeginSourceFileAction(CompilerInstance &CI,
   StringRef Filename) {
   CI.getLangOpts().CompilingPCH = true;

Modified: cfe/trunk/test/Index/pch-from-libclang.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/pch-from-libclang.c?rev=296320&r1=296319&r2=296320&view=diff
==
--- cfe/trunk/test/Index/pch-from-libclang.c (original)
+++ cfe/trunk/test/Index/pch-from-libclang.c Sun Feb 26 21:52:36 2017
@@ -6,18 +6,21 @@
 // RUN: %clang_cc1 -fsyntax-only %s -verify
 // RUN: c-index-test -write-pch %t.h.pch %s -fmodules 
-fmodules-cache-path=%t.mcp -Xclang -triple -Xclang x86_64-apple-darwin
 // RUN: %clang -fsyntax-only -include %t.h %s -Xclang -verify -fmodules 
-fmodules-cache-path=%t.mcp -Xclang -detailed-preprocessing-record -Xclang 
-triple -Xclang x86_64-apple-darwin -Xclang -fallow-pch-with-compiler-errors
+// RUN: %clang -x c-header %s -o %t.clang.h.pch -fmodules 
-fmodules-cache-path=%t.mcp -Xclang -detailed-preprocessing-record -Xclang 
-triple -Xclang x86_64-apple-darwin -Xclang -fallow-pch-with-compiler-errors 
-Xclang -verify
+// RUN: c-index-test -test-load-source local %s -include %t.clang.h -fmodules 
-fmodules-cache-path=%t.mcp -Xclang -triple -Xclang x86_64-apple-darwin | 
FileCheck %s
 
 #ifndef HEADER
 #define HEADER
 
-struct S { int x; };
-
 void some_function(undeclared_type p); // expected-error{{unknown type name}}
 
+struct S { int x; };
+
 #else
 // expected-no-diagnostics
 
 void test(struct S *s) {
+  // CHECK: [[@LINE+1]]:6: MemberRefExpr=x:[[@LINE-6]]:16
   s->x = 0;
 }
 


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


[PATCH] D30373: [analyzer] NFC: Update test infrastructure to support multiple constraint managers

2017-02-26 Thread Dominic Chen via Phabricator via cfe-commits
ddcc reopened this revision.
ddcc added a comment.
This revision is now accepted and ready to land.

Looks like there were four latent test failures that had been masked due to the 
way they were written. Here's the new version.


Repository:
  rL LLVM

https://reviews.llvm.org/D30373



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


[PATCH] D27627: [WIP] Specify default address space for C++ on AMDGPU Target

2017-02-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 89834.
yaxunl retitled this revision from "Allow target to specify default address 
space for codegen" to "[WIP] Specify default address space for C++ on AMDGPU 
Target".
yaxunl added a comment.
Herald added subscribers: tpr, dstuttard, kzhuravl.

Synch up to trunk.
Change bitcast to pointer cast in varous places to accommodation   addr space 
difference.


https://reviews.llvm.org/D27627

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/TargetInfo.h
  lib/AST/ASTContext.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGVTT.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/ItaniumCXXABI.cpp

Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1108,7 +1108,7 @@
 if (!Record->hasTrivialDestructor()) {
   CXXDestructorDecl *DtorD = Record->getDestructor();
   Dtor = CGM.getAddrOfCXXStructor(DtorD, StructorType::Complete);
-  Dtor = llvm::ConstantExpr::getBitCast(Dtor, CGM.Int8PtrTy);
+  Dtor = llvm::ConstantExpr::getPointerCast(Dtor, CGM.Int8PtrTy);
 }
   }
   if (!Dtor) Dtor = llvm::Constant::getNullValue(CGM.Int8PtrTy);
@@ -2171,7 +2171,7 @@
 
   llvm::Value *args[] = {
 llvm::ConstantExpr::getBitCast(dtor, dtorTy),
-llvm::ConstantExpr::getBitCast(addr, CGF.Int8PtrTy),
+llvm::ConstantExpr::getPointerCast(addr, CGF.Int8PtrTy),
 handle
   };
   CGF.EmitNounwindRuntimeCall(atexit, args);
@@ -2584,7 +2584,7 @@
 }
   }
 
-  return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
+  return llvm::ConstantExpr::getPointerCast(GV, CGM.Int8PtrTy);
 }
 
 /// TypeInfoIsInStandardLibrary - Given a builtin type, returns whether the type
@@ -2913,7 +2913,7 @@
   llvm::Constant *Two = llvm::ConstantInt::get(PtrDiffTy, 2);
   VTable =
   llvm::ConstantExpr::getInBoundsGetElementPtr(CGM.Int8PtrTy, VTable, Two);
-  VTable = llvm::ConstantExpr::getBitCast(VTable, CGM.Int8PtrTy);
+  VTable = llvm::ConstantExpr::getPointerCast(VTable, CGM.Int8PtrTy);
 
   Fields.push_back(VTable);
 }
@@ -2986,7 +2986,7 @@
 assert(!OldGV->hasAvailableExternallyLinkage() &&
"available_externally typeinfos not yet implemented");
 
-return llvm::ConstantExpr::getBitCast(OldGV, CGM.Int8PtrTy);
+return llvm::ConstantExpr::getPointerCast(OldGV, CGM.Int8PtrTy);
   }
 
   // Check if there is already an external RTTI descriptor for this type.
@@ -3022,7 +3022,7 @@
 TypeNameField =
 llvm::ConstantExpr::getIntToPtr(TypeNameField, CGM.Int8PtrTy);
   } else {
-TypeNameField = llvm::ConstantExpr::getBitCast(TypeName, CGM.Int8PtrTy);
+TypeNameField = llvm::ConstantExpr::getPointerCast(TypeName, CGM.Int8PtrTy);
   }
   Fields.push_back(TypeNameField);
 
@@ -3177,7 +3177,7 @@
 }
   }
 
-  return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
+  return llvm::ConstantExpr::getPointerCast(GV, CGM.Int8PtrTy);
 }
 
 /// BuildObjCObjectTypeInfo - Build the appropriate kind of type_info
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -47,6 +47,7 @@
 #include "llvm/ADT/Triple.h"
 #include "llvm/IR/CallSite.h"
 #include "llvm/IR/CallingConv.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/LLVMContext.h"
@@ -750,7 +751,7 @@
 ctor.addInt(Int32Ty, I.Priority);
 ctor.add(llvm::ConstantExpr::getBitCast(I.Initializer, CtorPFTy));
 if (I.AssociatedData)
-  ctor.add(llvm::ConstantExpr::getBitCast(I.AssociatedData, VoidPtrTy));
+  ctor.add(llvm::ConstantExpr::getPointerCast(I.AssociatedData, VoidPtrTy));
 else
   ctor.addNullPointer(VoidPtrTy);
 ctor.finishAndAddTo(ctors);
@@ -1418,10 +1419,13 @@
  *LineNoCst = EmitAnnotationLineNo(L);
 
   // Create the ConstantStruct for the global annotation.
+  unsigned AS = GV->getType()->getAddressSpace();
+  llvm::PointerType *I8PTy = (AS == Int8PtrTy->getAddressSpace()) ?
+Int8PtrTy : Int8Ty->getPointerTo(AS);
   llvm::Constant *Fields[4] = {
-llvm::ConstantExpr::getBitCast(GV, Int8PtrTy),
-llvm::ConstantExpr::getBitCast(AnnoGV, Int8PtrTy),
-llvm::ConstantExpr::getBitCast(UnitGV, Int8PtrTy),
+llvm::ConstantExpr::getPointerCast(GV, I8PTy),
+llvm::ConstantExpr::getPointerCast(AnnoGV, I8PTy),
+llvm::ConstantExpr::getPointerCast(UnitGV, I8PTy),
 LineNoCst
   };
   return llvm::ConstantStruct::getAnon(Fields);
@@ -1548,7 +1552,7 @@
   llvm::GlobalValue *Entry = GetGlobalValue(AA->getAlias

[PATCH] D30393: Do not inherit default arguments for friend function in class template.

2017-02-26 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.

A function declared in a friend declaration may have declarations prior
to the containing class definition. If such declaration defines default
argument, the friend function declaration inherits them. This behavior
causes problems if the class where the friend is declared is a template:
during the class instantiation the friend function looks like if it had
default arguments, so error is triggered.

With this change friend functions declared in class templates do not
inherit default arguments. Actual set of them will be defined at the
point where the containing class is instantiated.

This change fixes PR12724.


https://reviews.llvm.org/D30393

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp


Index: test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
===
--- test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
+++ test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
@@ -73,3 +73,36 @@
 }
 
 } // namespace
+
+namespace pr12724 {
+
+void func_01(bool param = true);
+class C01 {
+public:
+  friend void func_01(bool param);
+};
+
+void func_02(bool param = true);
+template
+class C02 {
+public:
+  friend void func_02(bool param);
+};
+C02 c02;
+
+void func_03(bool param);
+template
+class C03 {
+public:
+  friend void func_03(bool param);
+};
+void func_03(bool param = true);
+C03 c03;
+
+void main() {
+  func_01();
+  func_02();
+  func_03();
+}
+
+} // namespace pr12724
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -547,17 +547,23 @@
   Diag(OldParam->getLocation(), diag::note_previous_definition)
 << OldParam->getDefaultArgRange();
 } else if (OldParamHasDfl) {
-  // Merge the old default argument into the new parameter.
-  // It's important to use getInit() here;  getDefaultArg()
-  // strips off any top-level ExprWithCleanups.
-  NewParam->setHasInheritedDefaultArg();
-  if (OldParam->hasUnparsedDefaultArg())
-NewParam->setUnparsedDefaultArg();
-  else if (OldParam->hasUninstantiatedDefaultArg())
-NewParam->setUninstantiatedDefaultArg(
-  OldParam->getUninstantiatedDefaultArg());
-  else
-NewParam->setDefaultArg(OldParam->getInit());
+  // Merge the old default argument into the new parameter unless the new
+  // function is a friend declaration in a template class. In the latter
+  // case the default arguments will be inherited when the friend
+  // declaration will be instantiated.
+  if (New->getFriendObjectKind() == Decl::FOK_None ||
+  !New->getLexicalDeclContext()->isDependentContext()) {
+// It's important to use getInit() here;  getDefaultArg()
+// strips off any top-level ExprWithCleanups.
+NewParam->setHasInheritedDefaultArg();
+if (OldParam->hasUnparsedDefaultArg())
+  NewParam->setUnparsedDefaultArg();
+else if (OldParam->hasUninstantiatedDefaultArg())
+  NewParam->setUninstantiatedDefaultArg(
+   
OldParam->getUninstantiatedDefaultArg());
+else
+  NewParam->setDefaultArg(OldParam->getInit());
+  }
 } else if (NewParamHasDfl) {
   if (New->getDescribedFunctionTemplate()) {
 // Paragraph 4, quoted above, only applies to non-template functions.


Index: test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
===
--- test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
+++ test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
@@ -73,3 +73,36 @@
 }
 
 } // namespace
+
+namespace pr12724 {
+
+void func_01(bool param = true);
+class C01 {
+public:
+  friend void func_01(bool param);
+};
+
+void func_02(bool param = true);
+template
+class C02 {
+public:
+  friend void func_02(bool param);
+};
+C02 c02;
+
+void func_03(bool param);
+template
+class C03 {
+public:
+  friend void func_03(bool param);
+};
+void func_03(bool param = true);
+C03 c03;
+
+void main() {
+  func_01();
+  func_02();
+  func_03();
+}
+
+} // namespace pr12724
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -547,17 +547,23 @@
   Diag(OldParam->getLocation(), diag::note_previous_definition)
 << OldParam->getDefaultArgRange();
 } else if (OldParamHasDfl) {
-  // Merge the old default argument into the new parameter.
-  // It's important to use getInit() here;  getDefaultArg()
-  // strips off any top-level ExprWithCleanups.
-  NewParam->setHasInheritedDefaultArg();
-  if (OldParam->hasUnparsedDefaultArg())
-NewParam->setUnparsedDefaultArg();
-  else if (OldParam->hasUninstantiatedDefaultArg())
-New

[PATCH] D30372: [Driver] Consolidate tools and toolchains by target platform. (NFC)

2017-02-26 Thread David L. Jones via Phabricator via cfe-commits
dlj added a comment.

In https://reviews.llvm.org/D30372#686871, @ahatanak wrote:

> Have you considered using "include_directories" in CMakeLists.txt to avoid 
> including "../Something.h"?


I don't want to take that approach, and there's a specific reason why: my 
concern isn't with three extra bytes, it's the fact that the headers are in an 
unusual place. It's typical to include headers from a subdirectory, or from the 
includes directory, but far less common to include from a parent lib directory. 
Hiding that fact seems strictly worse to me.


https://reviews.llvm.org/D30372



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