[PATCH] D34591: [ubsan] Diagnose invalid uses of builtins (compiler-rt)

2017-06-23 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.
Herald added subscribers: dberris, kubamracek.

Compiler-rt changes and tests to go along with: https://reviews.llvm.org/D34590


https://reviews.llvm.org/D34591

Files:
  lib/ubsan/ubsan_checks.inc
  lib/ubsan/ubsan_handlers.cc
  lib/ubsan/ubsan_handlers.h
  lib/ubsan/ubsan_interface.inc
  test/ubsan/TestCases/Misc/builtins.cpp
  test/ubsan/lit.common.cfg

Index: test/ubsan/lit.common.cfg
===
--- test/ubsan/lit.common.cfg
+++ test/ubsan/lit.common.cfg
@@ -77,3 +77,5 @@
 # because the test hangs or fails on one configuration and not the other.
 if config.target_arch.startswith('arm') == False and config.target_arch != 'aarch64':
   config.available_features.add('stable-runtime')
+
+config.available_features.add('arch=' + config.target_arch)
Index: test/ubsan/TestCases/Misc/builtins.cpp
===
--- /dev/null
+++ test/ubsan/TestCases/Misc/builtins.cpp
@@ -0,0 +1,35 @@
+// REQUIRES: arch=x86_64
+//
+// RUN: %clangxx -fsanitize=builtin -w %s -O3 -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER
+// RUN: %clangxx -fsanitize=builtin -fno-sanitize-recover=builtin -w %s -O3 -o %t.abort
+// RUN: not %run %t.abort 2>&1 | FileCheck %s --check-prefix=ABORT
+
+void check_ctz(int n) {
+  // ABORT: builtins.cpp:[[@LINE+2]]:17: runtime error: passing zero to ctz(), which is not a valid argument
+  // RECOVER: builtins.cpp:[[@LINE+1]]:17: runtime error: passing zero to ctz(), which is not a valid argument
+  __builtin_ctz(n);
+
+  // RECOVER: builtins.cpp:[[@LINE+1]]:18: runtime error: passing zero to ctz(), which is not a valid argument
+  __builtin_ctzl(n);
+
+  // RECOVER: builtins.cpp:[[@LINE+1]]:19: runtime error: passing zero to ctz(), which is not a valid argument
+  __builtin_ctzll(n);
+}
+
+void check_clz(int n) {
+  // RECOVER: builtins.cpp:[[@LINE+1]]:17: runtime error: passing zero to clz(), which is not a valid argument
+  __builtin_clz(n);
+
+  // RECOVER: builtins.cpp:[[@LINE+1]]:18: runtime error: passing zero to clz(), which is not a valid argument
+  __builtin_clzl(n);
+
+  // RECOVER: builtins.cpp:[[@LINE+1]]:19: runtime error: passing zero to clz(), which is not a valid argument
+  __builtin_clzll(n);
+}
+
+int main() {
+  check_ctz(0);
+  check_clz(0);
+  return 0;
+}
Index: lib/ubsan/ubsan_interface.inc
===
--- lib/ubsan/ubsan_interface.inc
+++ lib/ubsan/ubsan_interface.inc
@@ -19,6 +19,8 @@
 INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow_abort)
 INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch)
 INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_abort)
+INTERFACE_FUNCTION(__ubsan_handle_invalid_builtin)
+INTERFACE_FUNCTION(__ubsan_handle_invalid_builtin_abort)
 INTERFACE_FUNCTION(__ubsan_handle_load_invalid_value)
 INTERFACE_FUNCTION(__ubsan_handle_load_invalid_value_abort)
 INTERFACE_FUNCTION(__ubsan_handle_missing_return)
Index: lib/ubsan/ubsan_handlers.h
===
--- lib/ubsan/ubsan_handlers.h
+++ lib/ubsan/ubsan_handlers.h
@@ -122,6 +122,21 @@
 /// \brief Handle a load of an invalid value for the type.
 RECOVERABLE(load_invalid_value, InvalidValueData *Data, ValueHandle Val)
 
+/// Known builtin check kinds.
+/// Keep in sync with the enum of the same name in CodeGenFunction.h
+enum BuiltinCheckKind : unsigned char {
+  BCK_CTZPassedZero,
+  BCK_CLZPassedZero,
+};
+
+struct InvalidBuiltinData {
+  SourceLocation Loc;
+  unsigned char Kind;
+};
+
+/// Handle a builtin called in an invalid way.
+RECOVERABLE(invalid_builtin, InvalidBuiltinData *Data)
+
 struct FunctionTypeMismatchData {
   SourceLocation Loc;
   const TypeDescriptor &Type;
Index: lib/ubsan/ubsan_handlers.cc
===
--- lib/ubsan/ubsan_handlers.cc
+++ lib/ubsan/ubsan_handlers.cc
@@ -437,6 +437,30 @@
   Die();
 }
 
+static void handleInvalidBuiltin(InvalidBuiltinData *Data, ReportOptions Opts) {
+  SourceLocation Loc = Data->Loc.acquire();
+  ErrorType ET = ErrorType::InvalidBuiltin;
+
+  if (ignoreReport(Loc, Opts, ET))
+return;
+
+  ScopedReport R(Opts, Loc, ET);
+
+  Diag(Loc, DL_Error,
+   "passing zero to %0, which is not a valid argument")
+<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
+}
+
+void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {
+  GET_REPORT_OPTIONS(true);
+  handleInvalidBuiltin(Data, Opts);
+}
+void __ubsan::__ubsan_handle_invalid_builtin_abort(InvalidBuiltinData *Data) {
+  GET_REPORT_OPTIONS(true);
+  handleInvalidBuiltin(Data, Opts);
+  Die();
+}
+
 static void handleFunctionTypeMismatch(FunctionTypeMismatchData *Data,
ValueHandle Function,
ReportOptions Opts) {
Index: lib/ubsan/ubsan_checks.inc
=

[PATCH] D34590: [ubsan] Diagnose invalid uses of builtins (clang)

2017-06-23 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

On some targets, passing zero to the clz() or ctz() builtins has
undefined behavior. I ran into this issue while debugging UB in
__hash_table from libcxx: the bug I was seeing manifested itself
differently under -O0 vs -Os, due to a UB call to clz() (see:
libcxx/r304617).

This patch introduces a check which can detect UB calls to builtins.

llvm.org/PR26979


https://reviews.llvm.org/D34590

Files:
  docs/UndefinedBehaviorSanitizer.rst
  include/clang/Basic/Sanitizers.def
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/ubsan-builtin-checks.c
  test/Driver/fsanitize.c

Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -3,27 +3,27 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize-undefined-trap-on-error -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
-// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}}
-// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
-// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
+// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute|function),?){19}"}}
+// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
+// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED
-// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
+// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){20}"}}
 
 // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
-// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
+// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
 
 // RUN: %clang -target i386-unknown-openbsd -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-OPENBSD
-// CHECK-UNDEFINED-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
+// CHECK-UNDEFINED-OPENBSD

[PATCH] D34574: [Sema] Disable c++17 aligned new and delete operators if not implemented in the deployment target's c++ standard library

2017-06-23 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D34574#789539, @ahatanak wrote:

> Is there any cases where we can turn the linker error into a compile time 
> error?


We could possibly implicitly put an availability attribute on the implicit 
declarations or something equivalent, to say "hey, we think your target doesn't 
support this" (but it'd still need to be a decision made by the driver and 
overridable by the user if they know better).


https://reviews.llvm.org/D34574



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


Re: [clang-tools-extra] r303735 - Modify test so that it looks for patterns in stderr as well

2017-06-23 Thread David Blaikie via cfe-commits
Ping (+Manuel, perhaps he's got some ideas about this, given background in
the tooling & compilation database work, or could point this to someone who
does?)

On Thu, Jun 15, 2017 at 10:40 AM David Blaikie  wrote:

> https://sarcasm.github.io/notes/dev/compilation-database.html#cmake
>
> If you enable the CMAKE_EXPORT_COMPILE_COMMANDS option in cmake (& have a
> sufficiently recent cmake), then CMake will generate a
> compile_commands.json in the root of the build tree. The test finds this &
> fails, instead of finding no compilation database & succeeding.
>
> (to use this, you can then symlink from the root of the source tree to
> point to this in your build tree - this is how I get YCM to work for my
> LLVM builds & could work for other clang tools as well)
>
> On Thu, Jun 15, 2017 at 7:51 AM Serge Pavlov  wrote:
>
>> 2017-06-15 2:43 GMT+07:00 David Blaikie :
>>
>>>
>>>
>>> On Wed, Jun 14, 2017, 8:17 AM Serge Pavlov  wrote:
>>>
 2017-06-14 4:24 GMT+07:00 David Blaikie :

> Ah, I find that the test passes if I remove the compile_commands.json
> file from my build directory (I have Ninja configured to generate a
> compile_commands.json file).
>
> Looks like what happens is it finds the compilation database and fails
> hard when the database doesn't contain a compile command for the file in
> question. If the database is not found, it falls back to some basic 
> command
> behavior, perhaps?
>
>
 You are right, constructor of `CommonOptionsParser` calls
 `autoDetectFromSource` or `autoDetectFromDirectory` prior to final
 construction of `FixedCompilationDatabase.

 Is there some way this test could be fixed to cope with this, otherwise
> it seems to get in the way of people actually using clang tools in their
> LLVM/Clang build environment?
>
>
 IIUC, presence of stale compilation database file in test directory
 could break many tests. I don't understand why only diagnostic.cpp fails,
 probably there is something wrong with the clang-tidy application cleanup
 in this case?

>>>
>>> Except it's neither stale nor in the test directory.
>>>
>>> It's the up to date/useful/used compile_commands.json generated by ninja
>>> in the root of the build tree.
>>>
>>
>> I miss something. If I could reproduce the problem, I would investigate
>> it.
>>
>>
>>>
>>>

> On Tue, Jun 13, 2017 at 7:41 AM Serge Pavlov 
> wrote:
>
>> I cannot reproduce such fail, so I can only guess how changes made in
>> https://reviews.llvm.org/rL303756 and
>> https://reviews.llvm.org/rL303741 could cause such problem. Behavior
>> of `Driver::BuildCompilation` is changed so that it returns null pointer 
>> if
>> errors occur during driver argument parse. It is called in
>> `CompilationDatabase.cpp` from `stripPositionalArgs`. The call stack at
>> this point is:
>> stripPositionalArgs
>> clang::tooling::FixedCompilationDatabase::loadFromCommandLine
>> clang::tooling::CommonOptionsParser::CommonOptionsParser
>> clang::tidy::clangTidyMain
>> main
>> `FixedCompilationDatabase::loadFromCommandLine` returns null and
>> CommonOptionsParser uses another method to create compilation database. 
>> The
>> output "Compile command not found" means that no input file were found in
>> `ClangTool::run`. Maybe some file names are nulls?
>>
>>
>> Thanks,
>> --Serge
>>
>> 2017-06-13 3:42 GMT+07:00 David Blaikie :
>>
>>> I've been seeing errors from this test recently:
>>>
>>> Command Output (stderr):
>>> --
>>> 1 error generated.
>>> Error while processing
>>> /usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp.nonexistent.cpp.
>>> /usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp:10:12:
>>> error: expected string not found in input
>>> // CHECK2: :[[@LINE+2]]:9: warning: implicit conversion from
>>> 'double' to 'int' changes value from 1.5 to 1
>>> [clang-diagnostic-literal-conversion]
>>>^
>>> :2:1: note: scanning from here
>>> Skipping
>>> /usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp.
>>> Compile command not found.
>>> ^
>>> :2:1: note: with expression "@LINE+2" equal to "12"
>>> Skipping
>>> /usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp.
>>> Compile command not found.
>>> ^
>>>
>>>
>>> Specifically, the output is:
>>> $ ./bin/clang-tidy
>>> -checks='-*,clang-diagnostic-*,google-explicit-constructor'
>>> /usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp
>>> -- -fan-unknown-option 2>&1error: unknown
>>> argument: '-fan-unknown-option'

[PATCH] D34588: Check for _MSC_VER before define _LIBCPP_MSVCRT

2017-06-23 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added reviewers: compnerd, majnemer, rnk.
smeenai added subscribers: majnemer, compnerd.
smeenai added a comment.

This looks sensible to me. I don't know if there are any scenarios in which 
you'd be using the Microsoft CRT without having `_MSC_VER` defined, however. 
Added some people who may have a better idea of that (@compnerd, @majnemer and 
@rnk)




Comment at: include/__config:234-235
+// a MS compatibility version is specified.
 #  ifndef __MINGW32__
-#define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
+#ifdef _MSC_VER
+#  define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library

You can combine this into just

```
#  if defined(_MSC_VER) && !defined(__MINGW32__)
```

I don't know if `__MINGW32__` and `_MSC_VER` will ever be compiled 
simultaneously. (clang never defines `_MSC_VER` for its MinGW triples, for 
example.)


https://reviews.llvm.org/D34588



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


[PATCH] D34588: Check for _MSC_VER before define _LIBCPP_MSVCRT

2017-06-23 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno created this revision.

_LIBCPP_MSVCRT is defined because _WIN32 is defined and __MINGW32__ is not.

Some non-windows targets using MS extensions define _WIN32 for compatibility 
with Windows but do not have MSVC compatibility. This patch is an attempt to do 
not have _LIBCPP_MSVCRT defined for such targets, allowing libcxx to build. 
This patch seems the natural way to go for me, but others more experienced here 
might have additional suggestions?


https://reviews.llvm.org/D34588

Files:
  include/__config


Index: include/__config
===
--- include/__config
+++ include/__config
@@ -229,9 +229,12 @@
 #  define _LIBCPP_SHORT_WCHAR   1
 // Both MinGW and native MSVC provide a "MSVC"-like enviroment
 #  define _LIBCPP_MSVCRT_LIKE
-// If mingw not explicitly detected, assume using MS C runtime only.
+// If mingw not explicitly detected, assume using MS C runtime only if
+// a MS compatibility version is specified.
 #  ifndef __MINGW32__
-#define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
+#ifdef _MSC_VER
+#  define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
+#endif
 #  endif
 #  if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || 
defined(__arm__))
 #define _LIBCPP_HAS_BITSCAN64


Index: include/__config
===
--- include/__config
+++ include/__config
@@ -229,9 +229,12 @@
 #  define _LIBCPP_SHORT_WCHAR   1
 // Both MinGW and native MSVC provide a "MSVC"-like enviroment
 #  define _LIBCPP_MSVCRT_LIKE
-// If mingw not explicitly detected, assume using MS C runtime only.
+// If mingw not explicitly detected, assume using MS C runtime only if
+// a MS compatibility version is specified.
 #  ifndef __MINGW32__
-#define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
+#ifdef _MSC_VER
+#  define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
+#endif
 #  endif
 #  if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
 #define _LIBCPP_HAS_BITSCAN64
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34415: Allow passing a regex for headers to exclude from clang-tidy

2017-06-23 Thread Todd Lipcon via Phabricator via cfe-commits
toddlipcon added a comment.

Anyone able to review this?


Repository:
  rL LLVM

https://reviews.llvm.org/D34415



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


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-23 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:981-984
+  Out << "YAXPAU__block_literal";
+  if (Discriminator)
+Out<< '_' << Discriminator;
+  Out << "@@@Z";

compnerd wrote:
> majnemer wrote:
> > I think you want to use mangleArtificalTagType here.
> I was considering that.  The addition of the `Discriminator` makes that 
> harder.  I can create a local buffer and create the name and then mangle that 
> though if you feel strongly about that.
I do, it will ensure it correctly backreferences.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-23 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

Ah, thanks for the explanation @efriedma.




Comment at: lib/AST/MicrosoftMangle.cpp:981-984
+  Out << "YAXPAU__block_literal";
+  if (Discriminator)
+Out<< '_' << Discriminator;
+  Out << "@@@Z";

majnemer wrote:
> I think you want to use mangleArtificalTagType here.
I was considering that.  The addition of the `Discriminator` makes that harder. 
 I can create a local buffer and create the name and then mangle that though if 
you feel strongly about that.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


[PATCH] D34574: [Sema] Disable c++17 aligned new and delete operators if not implemented in the deployment target's c++ standard library

2017-06-23 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

The motivation for this change was to silence linker errors I saw when 
compiling and linking programs in which operator new was called to allocate 
over-aligned types (similar to the code in cxx1z-aligned-allocation.cpp). 
Linkage failed because clang would emit the calls to the operator with 
alignment which were not implemented in the library.

I see now that it is probably not a good idea to disable this in the compiler 
for the two reasons you brought up.

Is there any cases where we can turn the linker error into a compile time error?


https://reviews.llvm.org/D34574



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


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-23 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:981-984
+  Out << "YAXPAU__block_literal";
+  if (Discriminator)
+Out<< '_' << Discriminator;
+  Out << "@@@Z";

I think you want to use mangleArtificalTagType here.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


r306183 - Add a warning to a group

2017-06-23 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Jun 23 18:34:32 2017
New Revision: 306183

URL: http://llvm.org/viewvc/llvm-project?rev=306183&view=rev
Log:
Add a warning to a group

Add warn_drv_object_size_disabled_O0 to the invalid command line
argument group. This should fix some bot failures:

  
lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/13241/steps/test/logs/stdio

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=306183&r1=306182&r2=306183&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Fri Jun 23 18:34:32 
2017
@@ -227,7 +227,8 @@ def warn_drv_disabling_vptr_no_rtti_defa
   "implicitly disabling vptr sanitizer because rtti wasn't enabled">,
   InGroup>;
 def warn_drv_object_size_disabled_O0 : Warning<
-  "the object size sanitizer has no effect at -O0, but is explicitly enabled: 
%0">;
+  "the object size sanitizer has no effect at -O0, but is explicitly enabled: 
%0">,
+  InGroup;
 
 def note_drv_command_failed_diag_msg : Note<
   "diagnostic msg: %0">;


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


[PATCH] D34580: [CodeGen][ObjC] Load indirect ARC arguments in prolog

2017-06-23 Thread Dave Lee via Phabricator via cfe-commits
kastiglione created this revision.

When generating a prolog, add loads for ARC arguments passed indirectly.


https://reviews.llvm.org/D34580

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenObjCXX/arc-indirect.mm


Index: test/CodeGenObjCXX/arc-indirect.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/arc-indirect.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc 
-fobjc-runtime=gnustep -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | 
FileCheck -check-prefixes CHECK,CHECK-GNUSTEP %s
+// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc 
-fobjc-runtime=macosx -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | 
FileCheck -check-prefixes CHECK,CHECK-DARWIN %s
+// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc 
-fobjc-runtime=ios -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | 
FileCheck -check-prefixes CHECK,CHECK-DARWIN %s
+
+// non trivially copyable, forces inalloca
+struct S {
+  S(const S &s) {}
+};
+
+@interface C
+@end
+@implementation C
+- (void)object:(id)obj struct:(S)s {
+}
+@end
+
+// CHECK-GNUSTEP: define internal void @_i_C__object_struct_(<{ %0*, i8*, i8*, 
%struct.S, [3 x i8] }>* inalloca)
+// CHECK-DARWIN: define internal void @"\01-[C object:struct:]"(<{ %0*, i8*, 
i8*, %struct.S, [3 x i8] }>* inalloca)
+// CHECK: %obj = getelementptr inbounds <{ %0*, i8*, i8*, %struct.S, [3 x i8] 
}>, <{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* %0, i32 0, i32 2
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1860,6 +1860,10 @@
 lt = Qualifiers::OCL_ExplicitNone;
   }
 
+  // Load objects passed indirectly.
+  if (Arg.isIndirect() && !ArgVal)
+ArgVal = Builder.CreateLoad(DeclPtr);
+
   if (lt == Qualifiers::OCL_Strong) {
 if (!isConsumed) {
   if (CGM.getCodeGenOpts().OptimizationLevel == 0) {


Index: test/CodeGenObjCXX/arc-indirect.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/arc-indirect.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc -fobjc-runtime=gnustep -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | FileCheck -check-prefixes CHECK,CHECK-GNUSTEP %s
+// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc -fobjc-runtime=macosx -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | FileCheck -check-prefixes CHECK,CHECK-DARWIN %s
+// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc -fobjc-runtime=ios -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | FileCheck -check-prefixes CHECK,CHECK-DARWIN %s
+
+// non trivially copyable, forces inalloca
+struct S {
+  S(const S &s) {}
+};
+
+@interface C
+@end
+@implementation C
+- (void)object:(id)obj struct:(S)s {
+}
+@end
+
+// CHECK-GNUSTEP: define internal void @_i_C__object_struct_(<{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* inalloca)
+// CHECK-DARWIN: define internal void @"\01-[C object:struct:]"(<{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* inalloca)
+// CHECK: %obj = getelementptr inbounds <{ %0*, i8*, i8*, %struct.S, [3 x i8] }>, <{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* %0, i32 0, i32 2
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1860,6 +1860,10 @@
 lt = Qualifiers::OCL_ExplicitNone;
   }
 
+  // Load objects passed indirectly.
+  if (Arg.isIndirect() && !ArgVal)
+ArgVal = Builder.CreateLoad(DeclPtr);
+
   if (lt == Qualifiers::OCL_Strong) {
 if (!isConsumed) {
   if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34563: [ubsan] Disable the object-size check at -O0

2017-06-23 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306181: [ubsan] Disable the object size check at -O0 
(authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D34563?vs=103778&id=103796#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34563

Files:
  cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
  cfe/trunk/lib/Driver/SanitizerArgs.cpp
  cfe/trunk/test/Driver/fsanitize-object-size.c
  cfe/trunk/test/Driver/fsanitize.c

Index: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
@@ -226,6 +226,8 @@
 def warn_drv_disabling_vptr_no_rtti_default : Warning<
   "implicitly disabling vptr sanitizer because rtti wasn't enabled">,
   InGroup>;
+def warn_drv_object_size_disabled_O0 : Warning<
+  "the object size sanitizer has no effect at -O0, but is explicitly enabled: %0">;
 
 def note_drv_command_failed_diag_msg : Note<
   "diagnostic msg: %0">;
Index: cfe/trunk/test/Driver/fsanitize-object-size.c
===
--- cfe/trunk/test/Driver/fsanitize-object-size.c
+++ cfe/trunk/test/Driver/fsanitize-object-size.c
@@ -0,0 +1,31 @@
+// Check that the object size check is disabled at -O0.
+//
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -O0 -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=null,object-size %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-OSIZE-NO-WARNING
+
+// Check that the object size check is enabled at other optimization levels.
+//
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -O1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O2 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O3 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O4 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Ofast %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Os %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Oz %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Og %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+
+// Use of trap mode shouldn't affect the object size check.
+//
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-trap=undefined -O1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -O1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error -O1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+
+// CHECK-HAS-OSIZE-NOT: warning: the object size sanitizer
+// CHECK-HAS-OSIZE: -fsanitize={{[^ ]*}}object-size
+
+// CHECK-NO-OSIZE: warning: the object size sanitizer has no effect at -O0, but is explicitly enabled: -fsanitize={{[^ ]*}}object-size
+// CHECK-NO-OSIZE-NOT: -fsanitize={{[^ ]*}}object-size
+
+// CHECK-NO-OSIZE-NO-WARNING-NOT: -fsanitize={{[^ ]*}}object-size
Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -3,27 +3,27 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize-undefined-trap-on-error -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
-// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){19}"}}
-// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,boo

r306181 - [ubsan] Disable the object size check at -O0

2017-06-23 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Jun 23 18:15:24 2017
New Revision: 306181

URL: http://llvm.org/viewvc/llvm-project?rev=306181&view=rev
Log:
[ubsan] Disable the object size check at -O0

This check currently isn't able to diagnose any issues at -O0, not is it
likely to [1]. Disabling the check at -O0 leads to substantial compile
time and binary size savings.

[1] [cfe-dev] Disabling ubsan's object size check at -O0

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

Added:
cfe/trunk/test/Driver/fsanitize-object-size.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=306181&r1=306180&r2=306181&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Fri Jun 23 18:15:24 
2017
@@ -226,6 +226,8 @@ def warn_drv_enabling_rtti_with_exceptio
 def warn_drv_disabling_vptr_no_rtti_default : Warning<
   "implicitly disabling vptr sanitizer because rtti wasn't enabled">,
   InGroup>;
+def warn_drv_object_size_disabled_O0 : Warning<
+  "the object size sanitizer has no effect at -O0, but is explicitly enabled: 
%0">;
 
 def note_drv_command_failed_diag_msg : Note<
   "diagnostic msg: %0">;

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=306181&r1=306180&r2=306181&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Fri Jun 23 18:15:24 2017
@@ -208,12 +208,28 @@ SanitizerArgs::SanitizerArgs(const ToolC
   SanitizerMask TrappingKinds = parseSanitizeTrapArgs(D, Args);
   SanitizerMask InvalidTrappingKinds = TrappingKinds & NotAllowedWithTrap;
 
+  // The object size sanitizer should not be enabled at -O0.
+  Arg *OptLevel = Args.getLastArg(options::OPT_O_Group);
+  bool RemoveObjectSizeAtO0 =
+  !OptLevel || OptLevel->getOption().matches(options::OPT_O0);
+
   for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
I != E; ++I) {
 const auto *Arg = *I;
 if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
   Arg->claim();
-  SanitizerMask Add = parseArgValues(D, Arg, true);
+  SanitizerMask Add = parseArgValues(D, Arg, /*AllowGroups=*/true);
+
+  if (RemoveObjectSizeAtO0) {
+AllRemove |= SanitizerKind::ObjectSize;
+
+// The user explicitly enabled the object size sanitizer. Warn that
+// that this does nothing at -O0.
+if (Add & SanitizerKind::ObjectSize)
+  D.Diag(diag::warn_drv_object_size_disabled_O0)
+  << Arg->getAsString(Args);
+  }
+
   AllAddedKinds |= expandSanitizerGroups(Add);
 
   // Avoid diagnosing any sanitizer which is disabled later.

Added: cfe/trunk/test/Driver/fsanitize-object-size.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-object-size.c?rev=306181&view=auto
==
--- cfe/trunk/test/Driver/fsanitize-object-size.c (added)
+++ cfe/trunk/test/Driver/fsanitize-object-size.c Fri Jun 23 18:15:24 2017
@@ -0,0 +1,31 @@
+// Check that the object size check is disabled at -O0.
+//
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -O0 -### 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=null,object-size %s -### 
2>&1 | FileCheck %s --check-prefixes=CHECK-NO-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | 
FileCheck %s --check-prefixes=CHECK-NO-OSIZE-NO-WARNING
+
+// Check that the object size check is enabled at other optimization levels.
+//
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -O1 %s -### 2>&1 
| FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O2 %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O3 %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O4 %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Ofast %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Os %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
+// RUN: %clang -target x86_

[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-23 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 103794.
compnerd added a comment.

This is a step in the right direction.  Although the NSDMI cases and default 
parameter value cases are not yet handled, they break due to tracking of the 
global mangling number tracking, not due to the scheme.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/msabi-blocks.cpp

Index: test/CodeGenCXX/msabi-blocks.cpp
===
--- /dev/null
+++ test/CodeGenCXX/msabi-blocks.cpp
@@ -0,0 +1,63 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -std=c++11 -fblocks -S -o - -emit-llvm %s | FileCheck %s
+
+void (^b)() = ^{
+  static int i = 0;
+};
+
+// CHECK-DAG: @"\01?i@?1??_block_invoke@@YAXPAU__block_literal@@@Z@4HA" ={{.*}} global i32 0
+
+extern int e(void);
+
+void f(void) {
+  static int i = 0;
+  ^{ static int i = e(); }();
+
+// CHECK-DAG: @"\01?i@?1??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0
+
+  ^{ static int i = e(); }();
+
+// CHECK-DAG: @"\01?i@?1??_block_invoke_2@@YAXPAU__block_literal_2@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0
+
+  ^{ ^{ static int i = e(); }(); }();
+
+// CHECK-DAG: @"\01?i@?1??_block_invoke_3@@YAXPAU__block_literal_3@@@Z?1??_block_invoke_4@@YAXPAU__block_literal_4@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0
+}
+
+
+template 
+void g(void) {
+  ^{ static int i = e(); }();
+}
+
+template void g(void);
+
+// CHECK-DAG: @"\01?i@?2??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?2???$g@D@@YAXXZ@4HA" ={{.*}} global i32 0
+
+template void g(void);
+
+// CHECK-DAG: @"\01?i@?2??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?2???$g@H@@YAXXZ@4HA" ={{.*}} global i32 0
+
+inline void h(void) {
+  ^{ static int i = e(); }();
+}
+
+// CHECK-DAG: @"\01?i@?2??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?2??h@@YAXXZ@4HA" ={{.*}} global i32 0
+
+#if 0
+struct s {
+  int i = ^{ static int i = e(); return ++i; }();
+  int j = ^{ static int i = e(); return ++i; }();
+
+  void m(int i = ^{ static int i = e(); return ++i; }(),
+ int j = ^{ static int i = e(); return ++i; }()) {}
+};
+#endif
+
+void j(void) {
+  h();
+#if 0
+  struct s s;
+  s.m();
+#endif
+}
+
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -966,16 +966,25 @@
 }
 
 if (const BlockDecl *BD = dyn_cast(DC)) {
-  DiagnosticsEngine &Diags = Context.getDiags();
-  unsigned DiagID =
-  Diags.getCustomDiagID(DiagnosticsEngine::Error,
-"cannot mangle a local inside this block yet");
-  Diags.Report(BD->getLocation(), DiagID);
-
-  // FIXME: This is completely, utterly, wrong; see ItaniumMangle
-  // for how this should be done.
-  Out << "__block_invoke" << Context.getBlockId(BD, false);
+  DC = getEffectiveDeclContext(BD);
+  unsigned Discriminator = BD->getBlockManglingNumber();
+  if (!Discriminator)
+Discriminator = Context.getBlockId(BD, /*Local=*/false);
+  Out << "?_block_invoke";
+  if (Discriminator)
+Out<< '_' << Discriminator;
   Out << '@';
+  if (const auto *RD = dyn_cast(DC))
+mangleName(RD);
+  else
+Out << '@';
+  Out << "YAXPAU__block_literal";
+  if (Discriminator)
+Out<< '_' << Discriminator;
+  Out << "@@@Z";
+  if (isa(DC))
+break;
+  continue;
 } else if (const ObjCMethodDecl *Method = dyn_cast(DC)) {
   mangleObjCMethodName(Method);
 } else if (isa(DC)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D34563: [ubsan] Disable the object-size check at -O0

2017-06-23 Thread Justin Bogner via cfe-commits
v...@apple.com writes:
> Good point, it makes sense to hand users a warning when they explicitly enable
> -fsanitize=object-size at -O0. I've added in the diagnostic. PTAL.

LGTM.

> diff --git a/include/clang/Basic/DiagnosticDriverKinds.td 
> b/include/clang/Basic/DiagnosticDriverKinds.td
> index 3833f0f28f..6ee061cca6 100644
> --- a/include/clang/Basic/DiagnosticDriverKinds.td
> +++ b/include/clang/Basic/DiagnosticDriverKinds.td
> @@ -226,6 +226,8 @@ def warn_drv_enabling_rtti_with_exceptions : Warning<
>  def warn_drv_disabling_vptr_no_rtti_default : Warning<
>"implicitly disabling vptr sanitizer because rtti wasn't enabled">,
>InGroup>;
> +def warn_drv_object_size_disabled_O0 : Warning<
> +  "the object size sanitizer has no effect at -O0, but is explicitly 
> enabled: %0">;
>  
>  def note_drv_command_failed_diag_msg : Note<
>"diagnostic msg: %0">;
> diff --git a/lib/Driver/SanitizerArgs.cpp b/lib/Driver/SanitizerArgs.cpp
> index d6a9c35eda..d5c27ccddd 100644
> --- a/lib/Driver/SanitizerArgs.cpp
> +++ b/lib/Driver/SanitizerArgs.cpp
> @@ -208,12 +208,28 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
>SanitizerMask TrappingKinds = parseSanitizeTrapArgs(D, Args);
>SanitizerMask InvalidTrappingKinds = TrappingKinds & NotAllowedWithTrap;
>  
> +  // The object size sanitizer should not be enabled at -O0.
> +  Arg *OptLevel = Args.getLastArg(options::OPT_O_Group);
> +  bool RemoveObjectSizeAtO0 =
> +  !OptLevel || OptLevel->getOption().matches(options::OPT_O0);
> +
>for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
> I != E; ++I) {
>  const auto *Arg = *I;
>  if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
>Arg->claim();
> -  SanitizerMask Add = parseArgValues(D, Arg, true);
> +  SanitizerMask Add = parseArgValues(D, Arg, /*AllowGroups=*/true);
> +
> +  if (RemoveObjectSizeAtO0) {
> +AllRemove |= SanitizerKind::ObjectSize;
> +
> +// The user explicitly enabled the object size check sanitizer. Warn
> +// them that this does nothing at -O0.
> +if (Add & SanitizerKind::ObjectSize)
> +  D.Diag(diag::warn_drv_object_size_disabled_O0)
> +  << Arg->getAsString(Args);
> +  }
> +
>AllAddedKinds |= expandSanitizerGroups(Add);
>  
>// Avoid diagnosing any sanitizer which is disabled later.
> diff --git a/test/Driver/fsanitize-object-size.c 
> b/test/Driver/fsanitize-object-size.c
> new file mode 100644
> index 00..ad8e27a9f4
> --- /dev/null
> +++ b/test/Driver/fsanitize-object-size.c
> @@ -0,0 +1,29 @@
> +// Check that the object size check is disabled at -O0.
> +//
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -### 2>&1 
> | FileCheck %s --check-prefix=CHECK-NO-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -O0 -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=null,object-size %s -### 
> 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | 
> FileCheck %s --check-prefixes=CHECK-NO-OSIZE-NO-WARNING
> +
> +// Check that the object size check is enabled at other optimization levels.
> +//
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -O1 %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O2 %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O3 %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O4 %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Ofast %s 
> -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Os %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Oz %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Og %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +
> +// Use of trap mode shouldn't affect the object size check.
> +//
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined 
> -fsanitize-trap=undefined -O1 %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -O1 %s 
> -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap 
> -fsanitize-undefined-trap-on-error -O1 %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-HAS-OSIZE
> +
> +// CHECK-HAS-OSIZE: -fsanitize={{[^ ]*}}object-size
> +
> +// CHECK-NO-OSIZE: warning: the o

[PATCH] D34578: cmath: Support clang's -fdelayed-template-parsing

2017-06-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.

r283051 added some functions to cmath (in namespace std) that have the same 
name as functions in math.h (in the global namespace).  Clang's limited support 
for `-fdelayed-template-parsing` chokes on this.  Rename the ones in `cmath` 
and their uses in `complex` and the test.

(Incidentally, I noticed that r283051 was optimizing the implementation of 
``.  I wonder why we have so much code in that header, instead of 
calling out to libc's already-optimized `` implementation?)

rdar://problem/32848355


https://reviews.llvm.org/D34578

Files:
  libcxx/include/cmath
  libcxx/include/complex
  libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp
  libcxx/test/libcxx/numerics/c.math/fdelayed-template-parsing.sh.cpp
  libcxx/utils/libcxx/test/config.py

Index: libcxx/utils/libcxx/test/config.py
===
--- libcxx/utils/libcxx/test/config.py
+++ libcxx/utils/libcxx/test/config.py
@@ -440,6 +440,9 @@
 # C++17 aligned allocation.
 self.config.available_features.add('no-aligned-allocation')
 
+if self.cxx.hasCompileFlag('-fdelayed-template-parsing'):
+self.config.available_features.add('fdelayed-template-parsing')
+
 if self.get_lit_bool('has_libatomic', False):
 self.config.available_features.add('libatomic')
 
Index: libcxx/test/libcxx/numerics/c.math/fdelayed-template-parsing.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/numerics/c.math/fdelayed-template-parsing.sh.cpp
@@ -0,0 +1,28 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// test that cmath builds with -fdelayed-template-parsing
+
+// REQUIRES: fdelayed-template-parsing
+
+// RUN: %build -fdelayed-template-parsing
+// RUN: %run
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+int main() {
+  assert(std::isfinite(1.0));
+  assert(!std::isinf(1.0));
+  assert(!std::isnan(1.0));
+}
+
+using namespace std;
Index: libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp
===
--- libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp
+++ libcxx/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp
@@ -23,9 +23,9 @@
 
 #include 
 
-static_assert(std::__libcpp_isnan(0.) == false, "");
-static_assert(std::__libcpp_isinf(0.0) == false, "");
-static_assert(std::__libcpp_isfinite(0.0) == true, "");
+static_assert(std::__libcpp_isnan_or_builtin(0.) == false, "");
+static_assert(std::__libcpp_isinf_or_builtin(0.0) == false, "");
+static_assert(std::__libcpp_isfinite_or_builtin(0.0) == true, "");
 
 int main()
 {
Index: libcxx/include/complex
===
--- libcxx/include/complex
+++ libcxx/include/complex
@@ -599,39 +599,39 @@
 _Tp __bc = __b * __c;
 _Tp __x = __ac - __bd;
 _Tp __y = __ad + __bc;
-if (__libcpp_isnan(__x) && __libcpp_isnan(__y))
+if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y))
 {
 bool __recalc = false;
-if (__libcpp_isinf(__a) || __libcpp_isinf(__b))
+if (__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b))
 {
-__a = copysign(__libcpp_isinf(__a) ? _Tp(1) : _Tp(0), __a);
-__b = copysign(__libcpp_isinf(__b) ? _Tp(1) : _Tp(0), __b);
-if (__libcpp_isnan(__c))
+__a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a);
+__b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b);
+if (__libcpp_isnan_or_builtin(__c))
 __c = copysign(_Tp(0), __c);
-if (__libcpp_isnan(__d))
+if (__libcpp_isnan_or_builtin(__d))
 __d = copysign(_Tp(0), __d);
 __recalc = true;
 }
-if (__libcpp_isinf(__c) || __libcpp_isinf(__d))
+if (__libcpp_isinf_or_builtin(__c) || __libcpp_isinf_or_builtin(__d))
 {
-__c = copysign(__libcpp_isinf(__c) ? _Tp(1) : _Tp(0), __c);
-__d = copysign(__libcpp_isinf(__d) ? _Tp(1) : _Tp(0), __d);
-if (__libcpp_isnan(__a))
+__c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c);
+__d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d);
+if (__libcpp_isnan_or_builtin(__a))
 __a = copysign(_Tp(0), __a);
-if (__libcpp_isnan(__b))
+if (__libcpp_isnan_or_builtin(__b))
 __b = copysign(_Tp(0), __b);
 __recalc = true;
 }
-if (!__recalc 

[PATCH] D33833: Fix PR 33189: Clang assertion on template destructor declaration

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



Comment at: test/SemaCXX/PR33189.cpp:1-7
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+class U
+{
+  template 
+  ~U() { } // expected-error{{destructor cannot be declared as a template}}
+};

Please fold this into an existing test file, perhaps 
`test/SemaTemplate/destructor-template.cpp`?


https://reviews.llvm.org/D33833



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


r306175 - Revert "[MS] Don't statically initialize dllimport member function pointers"

2017-06-23 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Jun 23 17:39:01 2017
New Revision: 306175

URL: http://llvm.org/viewvc/llvm-project?rev=306175&view=rev
Log:
Revert "[MS] Don't statically initialize dllimport member function pointers"

This reverts commit r306137. It has problems on code like this:

  struct __declspec(dllimport) Foo {
int a;
int get_a() { return a; }
  };
  template  struct HasValue {
int operator()(Foo *p) { return (p->*Getter)(); }
  };
  int main() {
Foo f;
f.a = 3;
int x = HasValue<&Foo::get_a>()(&f);
  }

Removed:
cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=306175&r1=306174&r2=306175&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Jun 23 17:39:01 2017
@@ -1665,19 +1665,6 @@ static bool CheckLValueConstantExpressio
   return true;
 }
 
-/// Member pointers are constant expressions unless they point to a
-/// non-virtual dllimport member function.
-static bool CheckMemberPointerConstantExpression(EvalInfo &Info,
- SourceLocation Loc,
- QualType Type,
- const APValue &Value) {
-  const ValueDecl *Member = Value.getMemberPointerDecl();
-  const auto *FD = dyn_cast_or_null(Member);
-  if (!FD)
-return true;
-  return FD->isVirtual() || !FD->hasAttr();
-}
-
 /// Check that this core constant expression is of literal type, and if not,
 /// produce an appropriate diagnostic.
 static bool CheckLiteralType(EvalInfo &Info, const Expr *E,
@@ -1770,9 +1757,6 @@ static bool CheckConstantExpression(Eval
 return CheckLValueConstantExpression(Info, DiagLoc, Type, LVal);
   }
 
-  if (Value.isMemberPointer())
-return CheckMemberPointerConstantExpression(Info, DiagLoc, Type, Value);
-
   // Everything else is fine.
   return true;
 }

Removed: cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp?rev=306174&view=auto
==
--- cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp (removed)
@@ -1,58 +0,0 @@
-// Also check that -Wglobal-constructors does the right thing. Strictly
-// speaking, this is a Sema test, but this avoids test case duplication.
-// RUN: %clang_cc1 -Wglobal-constructors %s -verify -triple i686-windows-msvc 
-fms-extensions -std=c++11
-//
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple i686-windows-msvc 
-fms-extensions -std=c++11 | FileCheck %s
-
-struct __declspec(dllimport) Single {
-  void nonvirt();
-  virtual void virt();
-};
-
-struct A { int a; };
-struct B { int b; };
-struct __declspec(dllimport) Multi : A, B {
-  void nonvirt();
-  virtual void virt();
-};
-
-struct __declspec(dllimport) Virtual : virtual A {
-  void nonvirt();
-  virtual void virt();
-};
-
-struct General;
-static_assert(sizeof(void (General::*)()) == 16, "force general memptr model");
-struct __declspec(dllimport) General {
-  void nonvirt();
-  virtual void virt();
-};
-
-auto mp_single_nv = &Single::nonvirt; // expected-warning {{global 
constructor}}
-auto mp_multi_nv = &Multi::nonvirt; // expected-warning {{global constructor}}
-auto mp_virtual_nv = &Virtual::nonvirt; // expected-warning {{global 
constructor}}
-auto mp_general_nv = &General::nonvirt; // expected-warning {{global 
constructor}}
-
-auto mp_single_v = &Single::virt;
-auto mp_multi_v = &Multi::virt;
-auto mp_virtual_v = &Virtual::virt;
-auto mp_general_v = &General::virt;
-
-// All of the non-virtual globals need dynamic initializers.
-
-// CHECK: @"\01?mp_single_nv@@3P8Single@@AEXXZQ1@" = global i8* null, align 4
-// CHECK: @"\01?mp_multi_nv@@3P8Multi@@AEXXZQ1@" = global { i8*, i32 } 
zeroinitializer, align 4
-// CHECK: @"\01?mp_virtual_nv@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 
} zeroinitializer, align 4
-// CHECK: @"\01?mp_general_nv@@3P8General@@AEXXZQ1@" = global { i8*, i32, i32, 
i32 } zeroinitializer, align 4
-
-// CHECK: @"\01?mp_single_v@@3P8Single@@AEXXZQ1@" = global i8* bitcast (void 
(%struct.Single*, ...)* @"\01??_9Single@@$BA@AE" to i8*), align 4
-// CHECK: @"\01?mp_multi_v@@3P8Multi@@AEXXZQ1@" = global { i8*, i32 } { i8* 
bitcast (void (%struct.Multi*, ...)* @"\01??_9Multi@@$BA@AE" to i8*), i32 0 }, 
align 4
-// CHECK: @"\01?mp_virtual_v@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 } 
{ i8* bitcast (void (%struct.Virtual*, ...)* @"\01??_9Virtual@@$BA@AE" to i8*), 
i32 0, i32 0 }, align 4
-// CHECK: @"\01?mp_general_v@@3P8General@@AEXXZQ1@" = global { i8*, i32, i32, 
i32 } { i8* bitcast (void (%struct.General

[PATCH] D33833: Fix PR 33189: Clang assertion on template destructor declaration

2017-06-23 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In https://reviews.llvm.org/D33833#789436, @kuang_he wrote:

> Can we get this patch reviewed by any chance?


@kuang_he; it is customary to "ping". In this case, "Ping 2".




Comment at: lib/AST/DeclCXX.cpp:1421
 
-  CXXDestructorDecl *Dtor = cast(R.front());
-  return Dtor;
+  return R.empty() ? nullptr : dyn_cast(R.front());
 }

I think what is here is probably what we want to do. My understanding is that 
the code is certainly invalid before we hit this, and the case is so odd that 
pursuing better recovery is not worthwhile.

Do we know if we can recover from getting a `FunctionTemplateDecl` by some 
other means? Perhaps by using the result of `getTemplatedDecl()`? I suspect 
there may be problems with cases where the //noexcept-specifier// is dependent.


https://reviews.llvm.org/D33833



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


[clang-tools-extra] r306172 - [clang-tidy] doc format fix

2017-06-23 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Fri Jun 23 17:12:55 2017
New Revision: 306172

URL: http://llvm.org/viewvc/llvm-project?rev=306172&view=rev
Log:
[clang-tidy] doc format fix

Summary: The url in the doc is wrong. Fix the url.

Reviewers: chh

Reviewed By: chh

Subscribers: srhines, xazax.hun

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=306172&r1=306171&r2=306172&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Fri Jun 23 17:12:55 2017
@@ -58,7 +58,7 @@ Improvements to clang-tidy
 --
 
 - New `android-file-open-flag
-`_ 
check
+  
`_ 
check
 
   Checks if the required file flag ``O_CLOEXEC`` exists in ``open()``,
   ``open64()`` and ``openat()``.


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


[PATCH] D34574: [Sema] Disable c++17 aligned new and delete operators if not implemented in the deployment target's c++ standard library

2017-06-23 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 103785.
ahatanak added a comment.

Remove -fno-aligned-allocation from the RUN lines. The test cases should check 
that new or delete operators with alignment are disabled without providing 
-fno-aligned-allocation.


https://reviews.llvm.org/D34574

Files:
  include/clang/Basic/TargetInfo.h
  lib/Basic/Targets.cpp
  lib/Sema/SemaExprCXX.cpp
  test/CodeGenCXX/cxx1z-aligned-allocation.cpp


Index: test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -3,10 +3,15 @@
 // RUN: %clang_cc1 -std=c++11 -fexceptions -fsized-deallocation 
-faligned-allocation %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s
 // RUN: %clang_cc1 -std=c++14 -fexceptions -fsized-deallocation 
-faligned-allocation %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s
 // RUN: %clang_cc1 -std=c++1z -fexceptions -fsized-deallocation %s -emit-llvm 
-triple x86_64-linux-gnu -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++1z -fexceptions -fsized-deallocation %s -emit-llvm 
-triple x86_64-apple-darwin10.13 -o - | FileCheck %s
 
 // Check that we don't used aligned (de)allocation without 
-faligned-allocation or C++1z.
 // RUN: %clang_cc1 -std=c++14 -DUNALIGNED -fexceptions %s -emit-llvm -triple 
x86_64-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-UNALIGNED
 // RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions -fno-aligned-allocation 
%s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s 
--check-prefix=CHECK-UNALIGNED
+// RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions  %s -emit-llvm -triple 
x86_64-apple-darwin10.12 -o - | FileCheck %s --check-prefix=CHECK-UNALIGNED
+// RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions %s -emit-llvm -triple 
arm64-apple-ios10 -o - | FileCheck %s --check-prefix=CHECK-UNALIGNED
+// RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions %s -emit-llvm -triple 
arm64-apple-tvos10 -o - | FileCheck %s --check-prefix=CHECK-UNALIGNED
+// RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions %s -emit-llvm -triple 
thumbv7k-apple-watchos4 -o - | FileCheck %s --check-prefix=CHECK-UNALIGNED
 
 // CHECK-UNALIGNED-NOT: _Znwm_St11align_val_t
 // CHECK-UNALIGNED-NOT: _Znam_St11align_val_t
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2580,7 +2580,8 @@
 // Create up to four variants of the function (sized/aligned).
 bool HasSizedVariant = getLangOpts().SizedDeallocation &&
(Kind == OO_Delete || Kind == OO_Array_Delete);
-bool HasAlignedVariant = getLangOpts().AlignedAllocation;
+bool HasAlignedVariant = getLangOpts().AlignedAllocation &&
+ 
!Context.getTargetInfo().disableAlignedAllocation();
 
 int NumSizeVariants = (HasSizedVariant ? 2 : 1);
 int NumAlignVariants = (HasAlignedVariant ? 2 : 1);
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -292,6 +292,29 @@
 // and therefore doesn't guarantee 16-byte alignment.
 return  64;
   }
+
+  bool disableAlignedAllocation() const override {
+unsigned Major, Minor, Micro;
+const llvm::Triple &T = this->getTriple();
+T.getOSVersion(Major, Minor, Micro);
+
+switch (T.getOS()) {
+case llvm::Triple::Darwin:
+case llvm::Triple::MacOSX: // Earlier than 10.13.
+  if (Major > 10)
+return false;
+  if (Major < 10)
+return true;
+  return Minor < 13;
+case llvm::Triple::IOS:
+case llvm::Triple::TvOS: // Earlier than 11.0.
+  return Major < 11;
+case llvm::Triple::WatchOS: // Earlier than 4.0.
+  return Major < 4;
+default:
+  llvm_unreachable("unexpected OS");
+}
+  }
 };
 
 
Index: include/clang/Basic/TargetInfo.h
===
--- include/clang/Basic/TargetInfo.h
+++ include/clang/Basic/TargetInfo.h
@@ -773,6 +773,14 @@
 return true;
   }
 
+  /// Returns true if the target doesn't support c++17's aligned new and
+  /// delete operators. For example, if the deployment target is old and the
+  /// operators are not available in the c++ standard library, this function
+  /// should return true.
+  virtual bool disableAlignedAllocation() const {
+return false;
+  }
+
   /// \brief Returns the target triple of the primary target.
   const llvm::Triple &getTriple() const {
 return Triple;


Index: test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -3,10 +3,15 @@
 // RUN: %clang_cc1 -std=c++11 -fexceptions -fsized-deallocation -faligned-allocation %s -emit-llvm -tr

[PATCH] D34574: [Sema] Disable c++17 aligned new and delete operators if not implemented in the deployment target's c++ standard library

2017-06-23 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Unlike with sized deallocation (which also requires a new stdlib entry point), 
it was intentional that this be enabled by default in C++17 mode. Implicit 
calls are only generated to the aligned forms of `operator new` and `operator 
delete` in cases where the program would otherwise be broken (due to requiring 
more alignment than the allocator would provide). A link error seems strictly 
preferable to silent misalignment at runtime. Plus, you have no way to tell 
whether the user is providing their own aligned allocation / deallocation 
functions, so disabling this by fiat for certain targets breaks legitimate use 
cases -- we need to at least respect the command-line `-faligned-allocation` 
flag and only use this target-based detection as a default / fallback.

What is the motivation for this change?




Comment at: include/clang/Basic/TargetInfo.h:780
+  /// should return true.
+  virtual bool disableAlignedAllocation() const {
+return false;

This is the wrong name for a `TargetInfo` member. The `TargetInfo` gets to say 
whether or not the target is known to support aligned allocation, but it's none 
of the target's business whether that support is ultimately enabled or 
disabled. Something like `supportsAlignedAllocation` would make more sense.



Comment at: lib/Sema/SemaExprCXX.cpp:2583-2584
(Kind == OO_Delete || Kind == OO_Array_Delete);
-bool HasAlignedVariant = getLangOpts().AlignedAllocation;
+bool HasAlignedVariant = getLangOpts().AlignedAllocation &&
+ 
!Context.getTargetInfo().disableAlignedAllocation();
 

The driver should be making this determination, not Sema. If -cc1 is invoked 
with aligned allocation enabled, we should not be overriding it here.


https://reviews.llvm.org/D34574



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


[PATCH] D33833: Fix PR 33189: Clang assertion on template destructor declaration

2017-06-23 Thread Kuang He via Phabricator via cfe-commits
kuang_he added a comment.

Can we get this patch reviewed by any chance?


https://reviews.llvm.org/D33833



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


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-23 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

>   How do we end up in a state where the block invocation function is 
> referenced external to the TU?

ODR allows certain definitions, like class definitions and inline function 
definitions, to be written in multiple translation units.  See 
http://itanium-cxx-abi.github.io/cxx-abi/abi.html#closure-types , specifically 
the list of cases where lambda types are required to correspond.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


[PATCH] D34574: [Sema] Disable c++17 aligned new and delete operators if not implemented in the deployment target's c++ standard library

2017-06-23 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.

This patch stops declaring implicitly the new and delete operators with 
alignment if the deployment target is earlier than the version in which support 
for them was introduced . This fixes linker errors which we see when the 
compiler emits a new or delete operator with alignment but the c++ library it 
links against is old and doesn't implement those operators.

I also sent a patch that annotates the declarations in libc++ today:

https://reviews.llvm.org/D34556

rdar://problem/32664169


https://reviews.llvm.org/D34574

Files:
  include/clang/Basic/TargetInfo.h
  lib/Basic/Targets.cpp
  lib/Sema/SemaExprCXX.cpp
  test/CodeGenCXX/cxx1z-aligned-allocation.cpp


Index: test/CodeGenCXX/cxx1z-aligned-allocation.cpp
===
--- test/CodeGenCXX/cxx1z-aligned-allocation.cpp
+++ test/CodeGenCXX/cxx1z-aligned-allocation.cpp
@@ -3,10 +3,15 @@
 // RUN: %clang_cc1 -std=c++11 -fexceptions -fsized-deallocation 
-faligned-allocation %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s
 // RUN: %clang_cc1 -std=c++14 -fexceptions -fsized-deallocation 
-faligned-allocation %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s
 // RUN: %clang_cc1 -std=c++1z -fexceptions -fsized-deallocation %s -emit-llvm 
-triple x86_64-linux-gnu -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++1z -fexceptions -fsized-deallocation %s -emit-llvm 
-triple x86_64-apple-darwin10.13 -o - | FileCheck %s
 
 // Check that we don't used aligned (de)allocation without 
-faligned-allocation or C++1z.
 // RUN: %clang_cc1 -std=c++14 -DUNALIGNED -fexceptions %s -emit-llvm -triple 
x86_64-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-UNALIGNED
 // RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions -fno-aligned-allocation 
%s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s 
--check-prefix=CHECK-UNALIGNED
+// RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions -fno-aligned-allocation 
%s -emit-llvm -triple x86_64-apple-darwin10.12 -o - | FileCheck %s 
--check-prefix=CHECK-UNALIGNED
+// RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions -fno-aligned-allocation 
%s -emit-llvm -triple arm64-apple-ios10 -o - | FileCheck %s 
--check-prefix=CHECK-UNALIGNED
+// RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions -fno-aligned-allocation 
%s -emit-llvm -triple arm64-apple-tvos10 -o - | FileCheck %s 
--check-prefix=CHECK-UNALIGNED
+// RUN: %clang_cc1 -std=c++1z -DUNALIGNED -fexceptions -fno-aligned-allocation 
%s -emit-llvm -triple thumbv7k-apple-watchos4 -o - | FileCheck %s 
--check-prefix=CHECK-UNALIGNED
 
 // CHECK-UNALIGNED-NOT: _Znwm_St11align_val_t
 // CHECK-UNALIGNED-NOT: _Znam_St11align_val_t
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2580,7 +2580,8 @@
 // Create up to four variants of the function (sized/aligned).
 bool HasSizedVariant = getLangOpts().SizedDeallocation &&
(Kind == OO_Delete || Kind == OO_Array_Delete);
-bool HasAlignedVariant = getLangOpts().AlignedAllocation;
+bool HasAlignedVariant = getLangOpts().AlignedAllocation &&
+ 
!Context.getTargetInfo().disableAlignedAllocation();
 
 int NumSizeVariants = (HasSizedVariant ? 2 : 1);
 int NumAlignVariants = (HasAlignedVariant ? 2 : 1);
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -292,6 +292,29 @@
 // and therefore doesn't guarantee 16-byte alignment.
 return  64;
   }
+
+  bool disableAlignedAllocation() const override {
+unsigned Major, Minor, Micro;
+const llvm::Triple &T = this->getTriple();
+T.getOSVersion(Major, Minor, Micro);
+
+switch (T.getOS()) {
+case llvm::Triple::Darwin:
+case llvm::Triple::MacOSX: // Earlier than 10.13.
+  if (Major > 10)
+return false;
+  if (Major < 10)
+return true;
+  return Minor < 13;
+case llvm::Triple::IOS:
+case llvm::Triple::TvOS: // Earlier than 11.0.
+  return Major < 11;
+case llvm::Triple::WatchOS: // Earlier than 4.0.
+  return Major < 4;
+default:
+  llvm_unreachable("unexpected OS");
+}
+  }
 };
 
 
Index: include/clang/Basic/TargetInfo.h
===
--- include/clang/Basic/TargetInfo.h
+++ include/clang/Basic/TargetInfo.h
@@ -773,6 +773,14 @@
 return true;
   }
 
+  /// Returns true if the target doesn't support c++17's aligned new and
+  /// delete operators. For example, if the deployment target is old and the
+  /// operators are not available in the c++ standard library, this function
+  /// should return true.
+  virtual bool disableAlignedAllocation() const {
+return false;
+  }
+
   /// \brief Returns the target triple of the primary target.
   const llvm::Triple &getTriple

Re: r304207 - Allow for unfinished #if blocks in preambles

2017-06-23 Thread Richard Smith via cfe-commits
On 23 June 2017 at 13:34, Benjamin Kramer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Since this change went in I'm seeing spurious errors whenever editing
> a header file, filed https://bugs.llvm.org/show_bug.cgi?id=33574 for
> that.


Does fixing the reversed condition I pointed out fix that?


> On Tue, May 30, 2017 at 1:54 PM, Erik Verbruggen via cfe-commits
>  wrote:
> > Author: erikjv
> > Date: Tue May 30 06:54:55 2017
> > New Revision: 304207
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=304207&view=rev
> > Log:
> > Allow for unfinished #if blocks in preambles
> >
> > Previously, a preamble only included #if blocks (and friends like
> > ifdef) if there was a corresponding #endif before any declaration or
> > definition. The problem is that any header file that uses include guards
> > will not have a preamble generated, which can make code-completion very
> > slow.
> >
> > To prevent errors about unbalanced preprocessor conditionals in the
> > preamble, and unbalanced preprocessor conditionals after a preamble
> > containing unfinished conditionals, the conditional stack is stored
> > in the pch file.
> >
> > This fixes PR26045.
> >
> > Differential Revision: http://reviews.llvm.org/D15994
> >
> >
> > Added:
> > cfe/trunk/test/Lexer/preamble2.c
> > Modified:
> > cfe/trunk/include/clang/Lex/Preprocessor.h
> > cfe/trunk/include/clang/Lex/PreprocessorLexer.h
> > cfe/trunk/include/clang/Lex/PreprocessorOptions.h
> > cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> > cfe/trunk/lib/Frontend/ASTUnit.cpp
> > cfe/trunk/lib/Lex/Lexer.cpp
> > cfe/trunk/lib/Lex/PPLexerChange.cpp
> > cfe/trunk/lib/Lex/Preprocessor.cpp
> > cfe/trunk/lib/Serialization/ASTReader.cpp
> > cfe/trunk/lib/Serialization/ASTWriter.cpp
> > cfe/trunk/test/Lexer/preamble.c
> >
> > Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Lex/Preprocessor.h?rev=304207&r1=304206&r2=304207&view=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
> > +++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue May 30 06:54:55 2017
> > @@ -283,6 +283,44 @@ class Preprocessor {
> >/// This is used when loading a precompiled preamble.
> >std::pair SkipMainFilePreamble;
> >
> > +  class PreambleConditionalStackStore {
> > +enum State {
> > +  Off = 0,
> > +  Recording = 1,
> > +  Replaying = 2,
> > +};
> > +
> > +  public:
> > +PreambleConditionalStackStore() : ConditionalStackState(Off) {}
> > +
> > +void startRecording() { ConditionalStackState = Recording; }
> > +void startReplaying() { ConditionalStackState = Replaying; }
> > +bool isRecording() const { return ConditionalStackState ==
> Recording; }
> > +bool isReplaying() const { return ConditionalStackState ==
> Replaying; }
> > +
> > +ArrayRef getStack() const {
> > +  return ConditionalStack;
> > +}
> > +
> > +void doneReplaying() {
> > +  ConditionalStack.clear();
> > +  ConditionalStackState = Off;
> > +}
> > +
> > +void setStack(ArrayRef s) {
> > +  if (!isRecording() && !isReplaying())
> > +return;
> > +  ConditionalStack.clear();
> > +  ConditionalStack.append(s.begin(), s.end());
> > +}
> > +
> > +bool hasRecordedPreamble() const { return
> !ConditionalStack.empty(); }
> > +
> > +  private:
> > +SmallVector ConditionalStack;
> > +State ConditionalStackState;
> > +  } PreambleConditionalStack;
> > +
> >/// \brief The current top of the stack that we're lexing from if
> >/// not expanding a macro and we are lexing directly from source code.
> >///
> > @@ -1695,6 +1733,11 @@ public:
> >/// \brief Return true if we're in the top-level file, not in a
> \#include.
> >bool isInPrimaryFile() const;
> >
> > +  /// \brief Return true if we're in the main file (specifically, if we
> are 0
> > +  /// (zero) levels deep \#include. This is used by the lexer to
> determine if
> > +  /// it needs to generate errors about unterminated \#if directives.
> > +  bool isInMainFile() const;
> > +
> >/// \brief Handle cases where the \#include name is expanded
> >/// from a macro as multiple tokens, which need to be glued together.
> >///
> > @@ -1932,6 +1975,27 @@ public:
> >Module *M,
> >
> SourceLocation MLoc);
> >
> > +  bool isRecordingPreamble() const {
> > +return PreambleConditionalStack.isRecording();
> > +  }
> > +
> > +  bool hasRecordedPreamble() const {
> > +return PreambleConditionalStack.hasRecordedPreamble();
> > +  }
> > +
> > +  ArrayRef getPreambleConditionalStack() const {
> > +  return PreambleConditionalStack.getStack();
> > +  }
> > +
> > +  void setRecordedPreambleConditionalStack(ArrayRef
> s) {
> > +PreambleConditionalStack.setStack(s);
> 

[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-23 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

@efriedma I think that Im still not understanding the case that you are trying 
to point out.  How do we end up in a state where the block invocation function 
is referenced external to the TU?  The block would be referenced to by name of 
the block, no?  AFAICT, this is for local storage in a block, which is scoped 
to the block invocation function, which is TU local, and will be referenced by 
the block_literal (which contains the block invocation function and is 
dispatched via the BlocksRuntime).


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


[PATCH] D34563: [ubsan] Disable the object-size check at -O0

2017-06-23 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 103778.
vsk added a comment.

Add a diagnostic for users who explicitly turn the object-size check on at -O0, 
and tighten up the test a bit.


https://reviews.llvm.org/D34563

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/SanitizerArgs.cpp
  test/Driver/fsanitize-object-size.c
  test/Driver/fsanitize.c

Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -3,27 +3,27 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize-undefined-trap-on-error -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
-// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){19}"}}
-// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
-// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
+// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}}
+// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
+// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED
-// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){20}"}}
+// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
 
 // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
-// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
+// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
 
 // RUN: %clang -target i386-unknown-openbsd -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-OPENBSD
-// CHECK-UNDEFINED-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
+// CHECK-UNDEFINED-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attrib

[clang-tools-extra] r306165 - [clang-tidy][Part1] Add a new module Android and three new checks.

2017-06-23 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Fri Jun 23 16:37:29 2017
New Revision: 306165

URL: http://llvm.org/viewvc/llvm-project?rev=306165&view=rev
Log:
[clang-tidy][Part1] Add a new module Android and three new checks.

Summary:
A common source of security bugs is code that opens a file descriptors without 
using the O_CLOEXEC flag.  (Without that flag, an opened sensitive file would 
remain open across a fork+exec to a lower-privileged SELinux domain, leaking 
that sensitive data.).

Add a new Android module and one checks in clang-tidy.
-- open(), openat(), and open64() should include O_CLOEXEC in their flags 
argument. [android-file-open-flag]

Links to part2 and part3:
https://reviews.llvm.org/D33745
https://reviews.llvm.org/D33747


Reviewers: chh, alexfh, aaron.ballman, hokein

Reviewed By: alexfh, hokein

Subscribers: jbcoe, joerg, malcolm.parsons, Eugene.Zelenko, srhines, mgorny, 
xazax.hun, cfe-commits, krytarowski

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/android/
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/android-file-open-flag.rst
clang-tools-extra/trunk/test/clang-tidy/android-file-open-flag.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
clang-tools-extra/trunk/docs/clang-tidy/index.rst
clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=306165&r1=306164&r2=306165&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Fri Jun 23 16:37:29 2017
@@ -26,6 +26,7 @@ add_clang_library(clangTidy
   clangToolingCore
   )
 
+add_subdirectory(android)
 add_subdirectory(boost)
 add_subdirectory(cert)
 add_subdirectory(cppcoreguidelines)

Added: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=306165&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Fri Jun 23 
16:37:29 2017
@@ -0,0 +1,40 @@
+//===--- AndroidTidyModule.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "FileOpenFlagCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// This module is for Android specific checks.
+class AndroidModule : public ClangTidyModule {
+public:
+  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("android-file-open-flag");
+  }
+};
+
+// Register the AndroidTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add
+X("android-module", "Adds Android platform checks.");
+
+} // namespace android
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the AndroidModule.
+volatile int AndroidModuleAnchorSource = 0;
+
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=306165&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Fri Jun 23 
16:37:29 2017
@@ -0,0 +1,14 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyAndroidModule
+  AndroidTidyModule.cpp
+  FileOpenFlagCheck.cpp
+
+  LINK_LIBS
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangLex
+  clangTidy
+  clangTidyUtils
+  )

Added: clang-tools-extra/trunk/clang-tid

[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

2017-06-23 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306163: [ubsan] Improve diagnostics for return value checks 
(clang) (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D34299?vs=103632&id=103774#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34299

Files:
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/CodeGen/CGStmt.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/CodeGenObjC/ubsan-nonnull-and-nullability.m
  cfe/trunk/test/CodeGenObjC/ubsan-nullability.m

Index: cfe/trunk/test/CodeGenObjC/ubsan-nonnull-and-nullability.m
===
--- cfe/trunk/test/CodeGenObjC/ubsan-nonnull-and-nullability.m
+++ cfe/trunk/test/CodeGenObjC/ubsan-nonnull-and-nullability.m
@@ -7,16 +7,26 @@
 // CHECK-LABEL: define nonnull i32* @f1
 __attribute__((returns_nonnull)) int *_Nonnull f1(int *_Nonnull p) {
   // CHECK: entry:
+  // CHECK-NEXT: [[SLOC_PTR:%.*]] = alloca i8*
   // CHECK-NEXT: [[ADDR:%.*]] = alloca i32*
+  // CHECK-NEXT: store i8* null, i8** [[SLOC_PTR]]
   // CHECK-NEXT: store i32* [[P:%.*]], i32** [[ADDR]]
+  // CHECK-NEXT: store {{.*}} [[SLOC_PTR]]
   // CHECK-NEXT: [[ARG:%.*]] = load i32*, i32** [[ADDR]]
+  // CHECK-NEXT: [[SLOC:%.*]] = load {{.*}} [[SLOC_PTR]]
+  // CHECK-NEXT: [[SLOC_NONNULL:%.*]] = icmp ne i8* [[SLOC]], null
+  // CHECK-NEXT: br i1 [[SLOC_NONNULL]], label %nullcheck
+  // 
+  // CHECK: nullcheck:
   // CHECK-NEXT: [[ICMP:%.*]] = icmp ne i32* [[ARG]], null, !nosanitize
   // CHECK-NEXT: br i1 [[ICMP]], label %[[CONT:.+]], label %[[HANDLE:[^,]+]]
   // CHECK: [[HANDLE]]:
-  // CHECK-NEXT:   call void @__ubsan_handle_nonnull_return_abort
+  // CHECK:  call void @__ubsan_handle_nonnull_return
   // CHECK-NEXT:   unreachable, !nosanitize
   // CHECK: [[CONT]]:
-  // CHECK-NEXT:   ret i32*
+  // CHECK-NEXT:   br label %no.nullcheck
+  // CHECK: no.nullcheck:
+  // CHECK-NEXT: ret i32* [[ARG]]
   return p;
 }
 
@@ -29,3 +39,23 @@
   // CHECK-NOT: call void @__ubsan_handle_nonnull_arg_abort
   f2((void *)0);
 }
+
+// If the return value isn't meant to be checked, make sure we don't check it.
+// CHECK-LABEL: define i32* @f3
+int *f3(int *p) {
+  // CHECK-NOT: return.sloc
+  // CHECK-NOT: call{{.*}}ubsan
+  return p;
+}
+
+// Check for a valid "return" source location, even when there is no return
+// statement, to avoid accidentally calling the runtime.
+
+// CHECK-LABEL: define nonnull i32* @f4
+__attribute__((returns_nonnull)) int *f4() {
+  // CHECK: store i8* null, i8** [[SLOC_PTR:%.*]]
+  // CHECK: [[SLOC:%.*]] = load {{.*}} [[SLOC_PTR]]
+  // CHECK: [[SLOC_NONNULL:%.*]] = icmp ne i8* [[SLOC]], null
+  // CHECK: br i1 [[SLOC_NONNULL]], label %nullcheck
+  // CHECK: nullcheck:
+}
Index: cfe/trunk/test/CodeGenObjC/ubsan-nullability.m
===
--- cfe/trunk/test/CodeGenObjC/ubsan-nullability.m
+++ cfe/trunk/test/CodeGenObjC/ubsan-nullability.m
@@ -2,31 +2,28 @@
 // RUN: %clang_cc1 -x objective-c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s
 // RUN: %clang_cc1 -x objective-c++ -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s
 
-// CHECK: [[NONNULL_RV_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 109, i32 1 {{.*}} i32 100, i32 6
+// CHECK: [[NONNULL_RV_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 100, i32 6
 // CHECK: [[NONNULL_ARG_LOC:@.*]] = private unnamed_addr global {{.*}} i32 204, i32 15 {{.*}} i32 190, i32 23
 // CHECK: [[NONNULL_ASSIGN1_LOC:@.*]] = private unnamed_addr global {{.*}} i32 305, i32 9
 // CHECK: [[NONNULL_ASSIGN2_LOC:@.*]] = private unnamed_addr global {{.*}} i32 405, i32 10
 // CHECK: [[NONNULL_ASSIGN3_LOC:@.*]] = private unnamed_addr global {{.*}} i32 506, i32 10
 // CHECK: [[NONNULL_INIT1_LOC:@.*]] = private unnamed_addr global {{.*}} i32 604, i32 25
 // CHECK: [[NONNULL_INIT2_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 707, i32 26
 // CHECK: [[NONNULL_INIT2_LOC2:@.*]] = private unnamed_addr global {{.*}} i32 707, i32 29
-// CHECK: [[NONNULL_RV_LOC2:@.*]] = private unnamed_addr global {{.*}} i32 817, i32 1 {{.*}} i32 800, i32 6
+// CHECK: [[NONNULL_RV_LOC2:@.*]] = private unnamed_addr global {{.*}} i32 800, i32 6
 
 #define NULL ((void *)0)
 #define INULL ((int *)NULL)
 #define INNULL ((int *_Nonnull)NULL)
 
 // CHECK-LABEL: define i32* @{{.*}}nonnull_retval1
 #line 100
 int *_Nonnull nonnull_retval1(int *p) {
-  // CHECK: br i1 true, label %[[NULL:.*]], label %[[NONULL:.*]], !nosanitize
-  // CHECK: [[NULL]]:
   // CHECK: [[ICMP:%.*]] = icmp ne i32* {{.*}}, null, !nosanitize
-  // CHECK-NEXT: br i1 [[ICMP]], {{.*}}, !nosanitize
+  // CHECK: br i1 [[ICMP]], {{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_nullability

r306163 - [ubsan] Improve diagnostics for return value checks (clang)

2017-06-23 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Jun 23 16:32:38 2017
New Revision: 306163

URL: http://llvm.org/viewvc/llvm-project?rev=306163&view=rev
Log:
[ubsan] Improve diagnostics for return value checks (clang)

This patch makes ubsan's nonnull return value diagnostics more precise,
which makes the diagnostics more useful when there are multiple return
statements in a function. Example:

1 |__attribute__((returns_nonnull)) char *foo() {
2 |  if (...) {
3 |return expr_which_might_evaluate_to_null();
4 |  } else {
5 |return another_expr_which_might_evaluate_to_null();
6 |  }
7 |} // <- The current diagnostic always points here!

runtime error: Null returned from Line 7, Column 2!
With this patch, the diagnostic would point to either Line 3, Column 5
or Line 5, Column 5.

This is done by emitting source location metadata for each return
statement in a sanitized function. The runtime is passed a pointer to
the appropriate metadata so that it can prepare and deduplicate reports.

Compiler-rt patch (with more tests): https://reviews.llvm.org/D34298

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

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenObjC/ubsan-nonnull-and-nullability.m
cfe/trunk/test/CodeGenObjC/ubsan-nullability.m

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=306163&r1=306162&r2=306163&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Jun 23 16:32:38 2017
@@ -2906,7 +2906,7 @@ void CodeGenFunction::EmitFunctionEpilog
 
   llvm::Instruction *Ret;
   if (RV) {
-EmitReturnValueCheck(RV, EndLoc);
+EmitReturnValueCheck(RV);
 Ret = Builder.CreateRet(RV);
   } else {
 Ret = Builder.CreateRetVoid();
@@ -2916,8 +2916,7 @@ void CodeGenFunction::EmitFunctionEpilog
 Ret->setDebugLoc(std::move(RetDbgLoc));
 }
 
-void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV,
-   SourceLocation EndLoc) {
+void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) {
   // A current decl may not be available when emitting vtable thunks.
   if (!CurCodeDecl)
 return;
@@ -2950,27 +2949,30 @@ void CodeGenFunction::EmitReturnValueChe
 
   SanitizerScope SanScope(this);
 
-  llvm::BasicBlock *Check = nullptr;
-  llvm::BasicBlock *NoCheck = nullptr;
-  if (requiresReturnValueNullabilityCheck()) {
-// Before doing the nullability check, make sure that the preconditions for
-// the check are met.
-Check = createBasicBlock("nullcheck");
-NoCheck = createBasicBlock("no.nullcheck");
-Builder.CreateCondBr(RetValNullabilityPrecondition, Check, NoCheck);
-EmitBlock(Check);
-  }
+  // Make sure the "return" source location is valid. If we're checking a
+  // nullability annotation, make sure the preconditions for the check are met.
+  llvm::BasicBlock *Check = createBasicBlock("nullcheck");
+  llvm::BasicBlock *NoCheck = createBasicBlock("no.nullcheck");
+  llvm::Value *SLocPtr = Builder.CreateLoad(ReturnLocation, 
"return.sloc.load");
+  llvm::Value *CanNullCheck = Builder.CreateIsNotNull(SLocPtr);
+  if (requiresReturnValueNullabilityCheck())
+CanNullCheck =
+Builder.CreateAnd(CanNullCheck, RetValNullabilityPrecondition);
+  Builder.CreateCondBr(CanNullCheck, Check, NoCheck);
+  EmitBlock(Check);
 
-  // Now do the null check. If the returns_nonnull attribute is present, this
-  // is done unconditionally.
+  // Now do the null check.
   llvm::Value *Cond = Builder.CreateIsNotNull(RV);
-  llvm::Constant *StaticData[] = {
-  EmitCheckSourceLocation(EndLoc), EmitCheckSourceLocation(AttrLoc),
-  };
-  EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, None);
-
-  if (requiresReturnValueNullabilityCheck())
-EmitBlock(NoCheck);
+  llvm::Constant *StaticData[] = {EmitCheckSourceLocation(AttrLoc)};
+  llvm::Value *DynamicData[] = {SLocPtr};
+  EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, DynamicData);
+
+  EmitBlock(NoCheck);
+
+#ifndef NDEBUG
+  // The return location should not be used after the check has been emitted.
+  ReturnLocation = Address::invalid();
+#endif
 }
 
 static bool isInAllocaArgument(CGCXXABI &ABI, QualType type) {

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=306163&r1=306162&r2=306163&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Fri Jun 23 16:32:38 2017
@@ -1024,6 +1024,18 @@ void CodeGenFunction::EmitReturnOfRValue
 /// if the function returns void, or may be missing one if the function returns
 /// non-void.  Fun stuff :

r306161 - [MSP430] Fix data layout string.

2017-06-23 Thread Vadzim Dambrouski via cfe-commits
Author: dambrouski
Date: Fri Jun 23 16:12:56 2017
New Revision: 306161

URL: http://llvm.org/viewvc/llvm-project?rev=306161&view=rev
Log:
[MSP430] Fix data layout string.

Summary:
Change data layout string so it would be compatible with MSP430 EABI.

Depends on D34561

Reviewers: asl, awygle

Reviewed By: asl

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/CodeGen/target-data.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=306161&r1=306160&r2=306161&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri Jun 23 16:12:56 2017
@@ -7503,7 +7503,7 @@ public:
 IntPtrType = SignedInt;
 PtrDiffType = SignedInt;
 SigAtomicType = SignedLong;
-resetDataLayout("e-m:e-p:16:16-i32:16:32-a:16-n8:16");
+resetDataLayout("e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16");
   }
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {

Modified: cfe/trunk/test/CodeGen/target-data.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/target-data.c?rev=306161&r1=306160&r2=306161&view=diff
==
--- cfe/trunk/test/CodeGen/target-data.c (original)
+++ cfe/trunk/test/CodeGen/target-data.c Fri Jun 23 16:12:56 2017
@@ -175,7 +175,7 @@
 
 // RUN: %clang_cc1 -triple msp430-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=MSP430
-// MSP430: target datalayout = "e-m:e-p:16:16-i32:16:32-a:16-n8:16"
+// MSP430: target datalayout = 
"e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"
 
 // RUN: %clang_cc1 -triple tce-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=TCE


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


[PATCH] D34562: [MSP430] Fix data layout string.

2017-06-23 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306161: [MSP430] Fix data layout string. (authored by 
dambrouski).

Changed prior to commit:
  https://reviews.llvm.org/D34562?vs=103751&id=103771#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34562

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/CodeGen/target-data.c


Index: cfe/trunk/test/CodeGen/target-data.c
===
--- cfe/trunk/test/CodeGen/target-data.c
+++ cfe/trunk/test/CodeGen/target-data.c
@@ -175,7 +175,7 @@
 
 // RUN: %clang_cc1 -triple msp430-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=MSP430
-// MSP430: target datalayout = "e-m:e-p:16:16-i32:16:32-a:16-n8:16"
+// MSP430: target datalayout = 
"e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"
 
 // RUN: %clang_cc1 -triple tce-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=TCE
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -7503,7 +7503,7 @@
 IntPtrType = SignedInt;
 PtrDiffType = SignedInt;
 SigAtomicType = SignedLong;
-resetDataLayout("e-m:e-p:16:16-i32:16:32-a:16-n8:16");
+resetDataLayout("e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16");
   }
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {


Index: cfe/trunk/test/CodeGen/target-data.c
===
--- cfe/trunk/test/CodeGen/target-data.c
+++ cfe/trunk/test/CodeGen/target-data.c
@@ -175,7 +175,7 @@
 
 // RUN: %clang_cc1 -triple msp430-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=MSP430
-// MSP430: target datalayout = "e-m:e-p:16:16-i32:16:32-a:16-n8:16"
+// MSP430: target datalayout = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"
 
 // RUN: %clang_cc1 -triple tce-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=TCE
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -7503,7 +7503,7 @@
 IntPtrType = SignedInt;
 PtrDiffType = SignedInt;
 SigAtomicType = SignedLong;
-resetDataLayout("e-m:e-p:16:16-i32:16:32-a:16-n8:16");
+resetDataLayout("e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16");
   }
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-23 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I think we just use "0" as a sentinel value to indicate the block doesn't need 
a mangling number.  getLambdaManglingNumber works the same way?  See 
CXXNameMangler::mangleUnqualifiedBlock in the Itanium mangler.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-23 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

@efriedma which bit of the Itanium mangling should I be looking at?  A 
BlockDecl does not have visibility associated with them, so Im not sure what I 
should be checking to see if the block is visible or not.  What is the best way 
forward for finishing this up?


Repository:
  rL LLVM

https://reviews.llvm.org/D34523



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


Re: [PATCH] D34563: [ubsan] Disable the object-size check at -O0

2017-06-23 Thread via cfe-commits
Good point, it makes sense to hand users a warning when they explicitly enable -fsanitize=object-size at -O0. I've added in the diagnostic. PTAL.


disable-object-size-check-O0.diff
Description: Binary data
vedantOn Jun 23, 2017, at 1:05 PM, Justin Bogner  wrote:+++ test/Driver/fsanitize-object-size.c@@ -0,0 +1,25 @@+// Check that the object size check is disabled at -O0.+//+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OSIZE+// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -O0 -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OSIZEThis isn't great - the user explicitly opted in to object-size but theydon't get it. We should either diagnose this and behave as is, or justenable the sanitizer even though it's not effective for forwardscompatibility.___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34523: AST: mangle BlockDecls under MS ABI

2017-06-23 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 103768.
compnerd added a comment.

Add additional test cases, improve coverage and mangling.


Repository:
  rL LLVM

https://reviews.llvm.org/D34523

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/msabi-blocks.cpp

Index: test/CodeGenCXX/msabi-blocks.cpp
===
--- /dev/null
+++ test/CodeGenCXX/msabi-blocks.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -std=c++11 -fblocks -S -o - -emit-llvm %s | FileCheck %s
+
+void (^b)() = ^{
+  static int i = 0;
+};
+
+// CHECK-DAG: @"\01?i@?1??_block_invoke@@YAXPAU__block_literal@@@Z@4HA" ={{.*}} global i32 0
+
+extern int e(void);
+
+void f(void) {
+  static int i = 0;
+  ^{ static int i = e(); }();
+
+// CHECK-DAG: @"\01?i@?1??_block_invoke_1@@YAXPAU__block_literal_1@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0
+
+  ^{ static int i = e(); }();
+
+// CHECK-DAG: @"\01?i@?1??_block_invoke_2@@YAXPAU__block_literal_2@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0
+
+  ^{ ^{ static int i = e(); }(); }();
+
+// CHECK-DAG: @"\01?i@?1??_block_invoke_3@@YAXPAU__block_literal_3@@@Z?1??_block_invoke_4@@YAXPAU__block_literal_4@@@Z?1??f@@YAXXZ@4HA" ={{.*}} global i32 0
+}
+
+
+template 
+void g(void) {
+  ^{ static int i = e(); }();
+}
+
+template void g(void);
+
+// CHECK-DAG: @"\01?i@?2??_block_invoke_5@@YAXPAU__block_literal_5@@@Z?2???$g@D@@YAXXZ@4HA" ={{.*}} global i32 0
+
+template void g(void);
+
+// CHECK-DAG: @"\01?i@?2??_block_invoke_6@@YAXPAU__block_literal_6@@@Z?2???$g@H@@YAXXZ@4HA" ={{.*}} global i32 0
+
+inline void h(void) {
+  ^{ static int i = e(); }();
+}
+
+// CHECK-DAG: @"\01?i@?2??_block_invoke_9@@YAXPAU__block_literal_9@@@Z?2??h@@YAXXZ@4HA" ={{.*}} global i32 0
+
+struct s {
+  int i = ^{ static int i = e(); return ++i; }();
+
+// CHECK-DAG: @"\01?i@?0??_block_invoke_10@s@@YAXPAU__block_literal_10@@@Z@4HA" ={{.*}} global i32 0
+
+  int j = ^{ static int i = e(); return ++i; }();
+
+// CHECK-DAG: @"\01?i@?0??_block_invoke_11@s@@YAXPAU__block_literal_11@@@Z@4HA" ={{.*}} global i32 0
+
+  void m(int i = ^{ static int i = e(); return ++i; }(),
+ int j = ^{ static int i = e(); return ++i; }()) {}
+
+// CHECK-DAG: @"\01?i@?0??_block_invoke_7@@YAXPAU__block_literal_7@@@Z?0??m@s@@QEAAXHH@Z@4HA" ={{.*}} global i32 0
+// CHECK-DAG: @"\01?i@?0??_block_invoke_8@@YAXPAU__block_literal_8@@@Z?0??m@s@@QEAAXHH@Z@4HA" ={{.*}} global i32 0
+};
+
+
+void j(void) {
+  h();
+  struct s s;
+  s.m();
+}
+
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -966,16 +966,23 @@
 }
 
 if (const BlockDecl *BD = dyn_cast(DC)) {
-  DiagnosticsEngine &Diags = Context.getDiags();
-  unsigned DiagID =
-  Diags.getCustomDiagID(DiagnosticsEngine::Error,
-"cannot mangle a local inside this block yet");
-  Diags.Report(BD->getLocation(), DiagID);
-
-  // FIXME: This is completely, utterly, wrong; see ItaniumMangle
-  // for how this should be done.
-  Out << "__block_invoke" << Context.getBlockId(BD, false);
+  DC = getEffectiveDeclContext(BD);
+  unsigned Discriminator = Context.getBlockId(BD, /*Local=*/false);
+  Out << "?_block_invoke";
+  if (Discriminator)
+Out<< '_' << Discriminator;
   Out << '@';
+  if (const auto *RD = dyn_cast(DC))
+mangleName(RD);
+  else
+Out << '@';
+  Out << "YAXPAU__block_literal";
+  if (Discriminator)
+Out<< '_' << Discriminator;
+  Out << "@@@Z";
+  if (isa(DC))
+break;
+  continue;
 } else if (const ObjCMethodDecl *Method = dyn_cast(DC)) {
   mangleObjCMethodName(Method);
 } else if (isa(DC)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r304207 - Allow for unfinished #if blocks in preambles

2017-06-23 Thread Benjamin Kramer via cfe-commits
Since this change went in I'm seeing spurious errors whenever editing
a header file, filed https://bugs.llvm.org/show_bug.cgi?id=33574 for
that.

On Tue, May 30, 2017 at 1:54 PM, Erik Verbruggen via cfe-commits
 wrote:
> Author: erikjv
> Date: Tue May 30 06:54:55 2017
> New Revision: 304207
>
> URL: http://llvm.org/viewvc/llvm-project?rev=304207&view=rev
> Log:
> Allow for unfinished #if blocks in preambles
>
> Previously, a preamble only included #if blocks (and friends like
> ifdef) if there was a corresponding #endif before any declaration or
> definition. The problem is that any header file that uses include guards
> will not have a preamble generated, which can make code-completion very
> slow.
>
> To prevent errors about unbalanced preprocessor conditionals in the
> preamble, and unbalanced preprocessor conditionals after a preamble
> containing unfinished conditionals, the conditional stack is stored
> in the pch file.
>
> This fixes PR26045.
>
> Differential Revision: http://reviews.llvm.org/D15994
>
>
> Added:
> cfe/trunk/test/Lexer/preamble2.c
> Modified:
> cfe/trunk/include/clang/Lex/Preprocessor.h
> cfe/trunk/include/clang/Lex/PreprocessorLexer.h
> cfe/trunk/include/clang/Lex/PreprocessorOptions.h
> cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> cfe/trunk/lib/Frontend/ASTUnit.cpp
> cfe/trunk/lib/Lex/Lexer.cpp
> cfe/trunk/lib/Lex/PPLexerChange.cpp
> cfe/trunk/lib/Lex/Preprocessor.cpp
> cfe/trunk/lib/Serialization/ASTReader.cpp
> cfe/trunk/lib/Serialization/ASTWriter.cpp
> cfe/trunk/test/Lexer/preamble.c
>
> Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=304207&r1=304206&r2=304207&view=diff
> ==
> --- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
> +++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue May 30 06:54:55 2017
> @@ -283,6 +283,44 @@ class Preprocessor {
>/// This is used when loading a precompiled preamble.
>std::pair SkipMainFilePreamble;
>
> +  class PreambleConditionalStackStore {
> +enum State {
> +  Off = 0,
> +  Recording = 1,
> +  Replaying = 2,
> +};
> +
> +  public:
> +PreambleConditionalStackStore() : ConditionalStackState(Off) {}
> +
> +void startRecording() { ConditionalStackState = Recording; }
> +void startReplaying() { ConditionalStackState = Replaying; }
> +bool isRecording() const { return ConditionalStackState == Recording; }
> +bool isReplaying() const { return ConditionalStackState == Replaying; }
> +
> +ArrayRef getStack() const {
> +  return ConditionalStack;
> +}
> +
> +void doneReplaying() {
> +  ConditionalStack.clear();
> +  ConditionalStackState = Off;
> +}
> +
> +void setStack(ArrayRef s) {
> +  if (!isRecording() && !isReplaying())
> +return;
> +  ConditionalStack.clear();
> +  ConditionalStack.append(s.begin(), s.end());
> +}
> +
> +bool hasRecordedPreamble() const { return !ConditionalStack.empty(); }
> +
> +  private:
> +SmallVector ConditionalStack;
> +State ConditionalStackState;
> +  } PreambleConditionalStack;
> +
>/// \brief The current top of the stack that we're lexing from if
>/// not expanding a macro and we are lexing directly from source code.
>///
> @@ -1695,6 +1733,11 @@ public:
>/// \brief Return true if we're in the top-level file, not in a \#include.
>bool isInPrimaryFile() const;
>
> +  /// \brief Return true if we're in the main file (specifically, if we are 0
> +  /// (zero) levels deep \#include. This is used by the lexer to determine if
> +  /// it needs to generate errors about unterminated \#if directives.
> +  bool isInMainFile() const;
> +
>/// \brief Handle cases where the \#include name is expanded
>/// from a macro as multiple tokens, which need to be glued together.
>///
> @@ -1932,6 +1975,27 @@ public:
>Module *M,
>SourceLocation 
> MLoc);
>
> +  bool isRecordingPreamble() const {
> +return PreambleConditionalStack.isRecording();
> +  }
> +
> +  bool hasRecordedPreamble() const {
> +return PreambleConditionalStack.hasRecordedPreamble();
> +  }
> +
> +  ArrayRef getPreambleConditionalStack() const {
> +  return PreambleConditionalStack.getStack();
> +  }
> +
> +  void setRecordedPreambleConditionalStack(ArrayRef s) {
> +PreambleConditionalStack.setStack(s);
> +  }
> +
> +  void setReplayablePreambleConditionalStack(ArrayRef s) {
> +PreambleConditionalStack.startReplaying();
> +PreambleConditionalStack.setStack(s);
> +  }
> +
>  private:
>// Macro handling.
>void HandleDefineDirective(Token &Tok, bool 
> ImmediatelyAfterTopLevelIfndef);
>
> Modified: cfe/trunk/include/clang/Lex/PreprocessorLexer.h
> U

r306156 - Add test for 306149, warn on throw from noexcept

2017-06-23 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Jun 23 15:30:33 2017
New Revision: 306156

URL: http://llvm.org/viewvc/llvm-project?rev=306156&view=rev
Log:
Add test for 306149, warn on throw from noexcept

Added:
cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp

Added: cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp?rev=306156&view=auto
==
--- cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp Fri Jun 23 15:30:33 
2017
@@ -0,0 +1,265 @@
+// RUN: %clang_cc1 %s  -fdelayed-template-parsing -fcxx-exceptions 
-fsyntax-only -Wexceptions -verify -std=c++11
+struct A_ShouldDiag {
+  ~A_ShouldDiag(); // implicitly noexcept(true)
+};
+A_ShouldDiag::~A_ShouldDiag() { // expected-note {{destructor or deallocator 
has a (possibly implicit) non-throwing excepton specification}}
+  throw 1; // expected-warning {{has a non-throwing exception specification 
but can still throw, resulting in unexpected program termination}}
+}
+struct B_ShouldDiag {
+  int i;
+  ~B_ShouldDiag() noexcept(true) {} //no disg, no throw stmt
+};
+struct R_ShouldDiag : A_ShouldDiag {
+  B_ShouldDiag b;
+  ~R_ShouldDiag() { // expected-note  {{destructor or deallocator has a}}
+throw 1; // expected-warning {{has a non-throwing exception specification 
but}}
+  }
+};
+
+struct M_ShouldNotDiag {
+  B_ShouldDiag b;
+  ~M_ShouldNotDiag() noexcept(false);
+};
+
+M_ShouldNotDiag::~M_ShouldNotDiag() noexcept(false) {
+  throw 1;
+}
+
+struct N_ShouldDiag {
+  B_ShouldDiag b;
+  ~N_ShouldDiag(); //implicitly noexcept(true)
+};
+
+N_ShouldDiag::~N_ShouldDiag() {  // expected-note  {{destructor or deallocator 
has a}}
+  throw 1; // expected-warning {{has a non-throwing exception specification 
but}}
+}
+struct X_ShouldDiag {
+  B_ShouldDiag b;
+  ~X_ShouldDiag() noexcept { // expected-note  {{destructor or deallocator has 
a}}
+throw 1;  // expected-warning {{has a non-throwing exception 
specification but}}
+  }
+};
+struct Y_ShouldDiag : A_ShouldDiag {
+  ~Y_ShouldDiag() noexcept(true) { // expected-note  {{destructor or 
deallocator has a}}
+throw 1;// expected-warning {{has a non-throwing exception 
specification but}}
+  }
+};
+struct C_ShouldNotDiag {
+  int i;
+  ~C_ShouldNotDiag() noexcept(false) {}
+};
+struct D_ShouldNotDiag {
+  C_ShouldNotDiag c;
+  ~D_ShouldNotDiag() { //implicitly noexcept(false)
+throw 1;
+  }
+};
+struct E_ShouldNotDiag  {
+  C_ShouldNotDiag c;
+  ~E_ShouldNotDiag(); //implicitly noexcept(false)
+};
+E_ShouldNotDiag::~E_ShouldNotDiag() //implicitly noexcept(false)
+{
+  throw 1;
+}
+
+template 
+class A1_ShouldDiag {
+  T b;
+
+public:
+  ~A1_ShouldDiag() {// expected-note  {{destructor or deallocator has a}}
+throw 1; // expected-warning {{has a non-throwing exception specification 
but}}
+  }
+};
+template 
+struct B1_ShouldDiag {
+  T i;
+  ~B1_ShouldDiag() noexcept(true) {}
+};
+template 
+struct R1_ShouldDiag : A1_ShouldDiag //expected-note {{in instantiation of 
member function}}
+{
+  B1_ShouldDiag b;
+  ~R1_ShouldDiag() {// expected-note  {{destructor or deallocator has a}}
+throw 1; // expected-warning {{has a non-throwing exception specification 
but}}
+  }
+};
+template 
+struct S1_ShouldDiag : A1_ShouldDiag {
+  B1_ShouldDiag b;
+  ~S1_ShouldDiag() noexcept { // expected-note  {{destructor or deallocator 
has a}}
+throw 1;   // expected-warning {{has a non-throwing exception 
specification but}}
+  }
+};
+void operator delete(void *ptr) noexcept { // expected-note  {{destructor or 
deallocator has a}}
+  throw 1; // expected-warning {{has a 
non-throwing exception specification but}}
+}
+struct except_fun {
+  static const bool i = false;
+};
+struct noexcept_fun {
+  static const bool i = true;
+};
+template 
+struct dependent_warn {
+  ~dependent_warn() noexcept(T::i) {
+throw 1;
+  }
+};
+template 
+struct dependent_warn_noexcept {
+  ~dependent_warn_noexcept() noexcept(T::i) { // expected-note  {{destructor 
or deallocator has a}}
+throw 1;  // expected-warning {{has a 
non-throwing exception specification but}}
+  }
+};
+template 
+struct dependent_warn_both {
+  ~dependent_warn_both() noexcept(T::i) { // expected-note  {{destructor or 
deallocator has a}}
+throw 1;  // expected-warning {{has a 
non-throwing exception specification but}}
+  }
+};
+void foo() noexcept { //expected-note {{non-throwing function declare here}}
+  throw 1;// expected-warning {{has a non-throwing exception 
specification but}}
+}
+struct Throws {
+  ~Throws() noexcept(false);
+};
+
+struct ShouldDiagnose {
+  Throws T;
+  ~ShouldDiagnose() noexcept { //expected-note {{destructor or deallocator has 
a}}
+throw;

[PATCH] D33333: Emit warning when throw exception in destruct or dealloc functions which has a (possible implicit) noexcept specifier

2017-06-23 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306149: Emit warning when throw exception in destruct or 
dealloc functions which has a  (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D3?vs=103519&id=103765#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D3

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
  cfe/trunk/test/CXX/except/except.spec/p11.cpp

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6351,6 +6351,15 @@
   "cannot use '%0' with exceptions disabled">;
 def err_objc_exceptions_disabled : Error<
   "cannot use '%0' with Objective-C exceptions disabled">;
+def warn_throw_in_noexcept_func 
+: Warning<"%0 has a non-throwing exception specification but can still "
+  "throw, resulting in unexpected program termination">,
+  InGroup;
+def note_throw_in_dtor 
+: Note<"destructor or deallocator has a (possibly implicit) non-throwing "
+  "excepton specification">;
+def note_throw_in_function 
+: Note<"non-throwing function declare here">;
 def err_seh_try_outside_functions : Error<
   "cannot use SEH '__try' in blocks, captured regions, or Obj-C method decls">;
 def err_mixing_cxx_try_seh_try : Error<
Index: cfe/trunk/test/CXX/except/except.spec/p11.cpp
===
--- cfe/trunk/test/CXX/except/except.spec/p11.cpp
+++ cfe/trunk/test/CXX/except/except.spec/p11.cpp
@@ -1,12 +1,11 @@
 // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 // This is the "let the user shoot themselves in the foot" clause.
-void f() noexcept {
-  throw 0; // no-error
+void f() noexcept { // expected-note {{non-throwing function declare here}}
+  throw 0; // expected-warning {{has a non-throwing exception specification but}} 
 }
-void g() throw() {
-  throw 0; // no-error
+void g() throw() { // expected-note {{non-throwing function declare here}}
+  throw 0; // expected-warning {{has a non-throwing exception specification but}} 
 }
 void h() throw(int) {
   throw 0.0; // no-error
Index: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
===
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
@@ -279,6 +279,150 @@
 }
 
 //===--===//
+// Check for throw in a non-throwing function.
+//===--===//
+enum ThrowState {
+  FoundNoPathForThrow,
+  FoundPathForThrow,
+  FoundPathWithNoThrowOutFunction,
+};
+
+static bool isThrowCaught(const CXXThrowExpr *Throw,
+  const CXXCatchStmt *Catch) {
+  const Type *ThrowType = nullptr;
+  if (Throw->getSubExpr())
+ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
+  if (!ThrowType)
+return false;
+  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+  if (!CaughtType)
+return true;
+  if (ThrowType->isReferenceType())
+ThrowType = ThrowType->castAs()
+->getPointeeType()
+->getUnqualifiedDesugaredType();
+  if (CaughtType->isReferenceType())
+CaughtType = CaughtType->castAs()
+ ->getPointeeType()
+ ->getUnqualifiedDesugaredType();
+  if (CaughtType == ThrowType)
+return true;
+  const CXXRecordDecl *CaughtAsRecordType =
+  CaughtType->getPointeeCXXRecordDecl();
+  const CXXRecordDecl *ThrowTypeAsRecordType = ThrowType->getAsCXXRecordDecl();
+  if (CaughtAsRecordType && ThrowTypeAsRecordType)
+return ThrowTypeAsRecordType->isDerivedFrom(CaughtAsRecordType);
+  return false;
+}
+
+static bool isThrowCaughtByHandlers(const CXXThrowExpr *CE,
+const CXXTryStmt *TryStmt) {
+  for (unsigned H = 0, E = TryStmt->getNumHandlers(); H < E; ++H) {
+if (isThrowCaught(CE, TryStmt->getHandler(H)))
+  return true;
+  }
+  return false;
+}
+
+static bool doesThrowEscapePath(CFGBlock Block, SourceLocation &OpLoc) {
+  for (const auto &B : Block) {
+if (B.getKind() != CFGElement::Statement)
+  continue;
+const auto *CE = dyn_cast(B.getAs()->getStmt());
+if (!CE)
+  continue;
+
+OpLoc = CE->getThrowLoc();
+for (const auto &I : Block.succs()) {
+  if (!I.isReachable())
+continue;
+  if (const auto *Terminator =
+  dyn_cast_or_null(I->getTerminator()))
+if (isThrowCaughtByHandlers(CE, Terminator))
+  return false;
+}
+return true;
+  }
+  return false;
+}
+
+static bool hasThrowOutNonThrowingFunc(SourceLocation &O

r306149 - Emit warning when throw exception in destruct or dealloc functions which has a

2017-06-23 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Jun 23 15:22:19 2017
New Revision: 306149

URL: http://llvm.org/viewvc/llvm-project?rev=306149&view=rev
Log:
Emit warning when throw exception in destruct or dealloc functions which has a 
(possible implicit) noexcept specifier

Throwing in the destructor is not good (C++11 change try to not allow see 
below).
 But in reality, those codes are exist.
C++11 [class.dtor]p3:

A declaration of a destructor that does not have an exception-specification is 
implicitly considered to have the same exception specification as an implicit 
declaration.

With this change, the application worked before may now run into runtime 
termination. My goal here is to emit a warning to provide only possible info to 
where the code may need to be changed.

First there is no way, in compile time to identify the “throw” really throw out 
of the function. Things like the call which throw out… To keep this simple, 
when “throw” is seen, checking its enclosing function(only destructor and 
dealloc functions) with noexcept(true) specifier emit warning.

Here is implementation detail:
A new member function CheckCXXThrowInNonThrowingFunc is added for class Sema 
in Sema.h. It is used in the call to both BuildCXXThrow and 
TransformCXXThrowExpr.

The function basic check if the enclosing function with non-throwing noexcept 
specifer, if so emit warning for it.

The example of warning message like:
k1.cpp:18:3: warning: ''~dependent_warn'' has a (possible implicit) non-throwing

noexcept specifier. Throwing exception may cause termination.
[-Wthrow-in-dtor]
throw 1;
^

k1.cpp:43:30: note: in instantiation of member function

'dependent_warn::~dependent_warn' requested here

dependent_warn f; // cause warning

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


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/CXX/except/except.spec/p11.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=306149&r1=306148&r2=306149&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 23 15:22:19 
2017
@@ -6351,6 +6351,15 @@ def err_exceptions_disabled : Error<
   "cannot use '%0' with exceptions disabled">;
 def err_objc_exceptions_disabled : Error<
   "cannot use '%0' with Objective-C exceptions disabled">;
+def warn_throw_in_noexcept_func 
+: Warning<"%0 has a non-throwing exception specification but can still "
+  "throw, resulting in unexpected program termination">,
+  InGroup;
+def note_throw_in_dtor 
+: Note<"destructor or deallocator has a (possibly implicit) non-throwing "
+  "excepton specification">;
+def note_throw_in_function 
+: Note<"non-throwing function declare here">;
 def err_seh_try_outside_functions : Error<
   "cannot use SEH '__try' in blocks, captured regions, or Obj-C method decls">;
 def err_mixing_cxx_try_seh_try : Error<

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=306149&r1=306148&r2=306149&view=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Fri Jun 23 15:22:19 2017
@@ -279,6 +279,150 @@ static void checkRecursiveFunction(Sema
 }
 
 
//===--===//
+// Check for throw in a non-throwing function.
+//===--===//
+enum ThrowState {
+  FoundNoPathForThrow,
+  FoundPathForThrow,
+  FoundPathWithNoThrowOutFunction,
+};
+
+static bool isThrowCaught(const CXXThrowExpr *Throw,
+  const CXXCatchStmt *Catch) {
+  const Type *ThrowType = nullptr;
+  if (Throw->getSubExpr())
+ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
+  if (!ThrowType)
+return false;
+  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+  if (!CaughtType)
+return true;
+  if (ThrowType->isReferenceType())
+ThrowType = ThrowType->castAs()
+->getPointeeType()
+->getUnqualifiedDesugaredType();
+  if (CaughtType->isReferenceType())
+CaughtType = CaughtType->castAs()
+ ->getPointeeType()
+ ->getUnqualifiedDesugaredType();
+  if (CaughtType == ThrowType)
+return true;
+  const CXXRecordDecl *CaughtAsRecordType =
+  CaughtType->getPointeeCXXRecordDecl();
+  const CXXRecordDecl *ThrowTypeAsRecordType = ThrowType->getAsCXXRecordDecl();
+  if (CaughtAsRecordType && ThrowType

[PATCH] D31575: [clang-format] Use configured IndentWidth instead of 2

2017-06-23 Thread Andrew Stone via Phabricator via cfe-commits
thatguystone closed this revision.
thatguystone added a comment.

A similar fix was accepted in https://reviews.llvm.org/D33857


https://reviews.llvm.org/D31575



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


[PATCH] D34568: [Sema] Make BreakContinueFinder handle nested loops.

2017-06-23 Thread Eli Friedman via Phabricator via cfe-commits
efriedma created this revision.

We don't care about break or continue statements that aren't
associated with the current loop, so make sure the visitor
doesn't find them.

Fixes https://bugs.llvm.org/show_bug.cgi?id=32648 .


Repository:
  rL LLVM

https://reviews.llvm.org/D34568

Files:
  lib/Sema/SemaStmt.cpp
  test/Sema/loop-control.c
  test/SemaCXX/warn-loop-analysis.cpp

Index: test/SemaCXX/warn-loop-analysis.cpp
===
--- test/SemaCXX/warn-loop-analysis.cpp
+++ test/SemaCXX/warn-loop-analysis.cpp
@@ -202,6 +202,12 @@
 if (true) continue;
 i--;
   }
+
+  // But do warn if the continue is in a nested loop.
+  for (;;i--) { // expected-note{{decremented here}}
+for (int j = 0; j < 10; ++j) continue;
+i--; // expected-warning{{decremented both}}
+  }
 }
 
 struct iterator {
@@ -259,6 +265,12 @@
 if (true) continue;
 i--;
   }
+
+  // But do warn if the continue is in a nested loop.
+  for (;;i--) { // expected-note{{decremented here}}
+for (int j = 0; j < 10; ++j) continue;
+i--; // expected-warning{{decremented both}}
+  }
 }
 
 int f(int);
Index: test/Sema/loop-control.c
===
--- test/Sema/loop-control.c
+++ test/Sema/loop-control.c
@@ -119,3 +119,51 @@
 for ( ; ({ ++y; break; y;}); ++y) {} // expected-warning{{'break' is bound to loop, GCC binds it to switch}}
   }
 }
+
+void pr32648_1(int x, int y) {
+  switch(x) {
+  case 1:
+for ( ; ({ ++y; switch (y) { case 0: break; } y;}); ++y) {} // no warning
+  }
+}
+
+void pr32648_2(int x, int y) {
+  while(x) {
+for ( ; ({ ++y; switch (y) { case 0: continue; } y;}); ++y) {}  // expected-warning {{'continue' is bound to current loop, GCC binds it to the enclosing loop}}
+  }
+}
+
+void pr32648_3(int x, int y) {
+  switch(x) {
+  case 1:
+for ( ; ({ ++y; for (; y; y++) { break; } y;}); ++y) {} // no warning
+  }
+}
+
+void pr32648_4(int x, int y) {
+  switch(x) {
+  case 1:
+for ( ; ({ ++y; for (({ break; }); y; y++) { } y;}); ++y) {} // expected-warning{{'break' is bound to loop, GCC binds it to switch}}
+  }
+}
+
+void pr32648_5(int x, int y) {
+  switch(x) {
+  case 1:
+for ( ; ({ ++y; while (({ break; y; })) {} y;}); ++y) {} // expected-warning{{'break' is bound to current loop, GCC binds it to the enclosing loop}}
+  }
+}
+
+void pr32648_6(int x, int y) {
+  switch(x) {
+  case 1:
+for ( ; ({ ++y; do {} while (({ break; y; })); y;}); ++y) {} // expected-warning{{'break' is bound to current loop, GCC binds it to the enclosing loop}}
+  }
+}
+
+void pr32648_7(int x, int y) {
+  switch(x) {
+  case 1:
+for ( ; ({ ++y; do { break; } while (y); y;}); ++y) {} // no warning
+  }
+}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1544,23 +1544,78 @@
 
   // A visitor to determine if a continue or break statement is a
   // subexpression.
-  class BreakContinueFinder : public EvaluatedExprVisitor {
+  class BreakContinueFinder : public ConstEvaluatedExprVisitor {
 SourceLocation BreakLoc;
 SourceLocation ContinueLoc;
+bool InSwitch = false;
+
   public:
-BreakContinueFinder(Sema &S, Stmt* Body) :
+BreakContinueFinder(Sema &S, const Stmt* Body) :
 Inherited(S.Context) {
   Visit(Body);
 }
 
-typedef EvaluatedExprVisitor Inherited;
+typedef ConstEvaluatedExprVisitor Inherited;
 
-void VisitContinueStmt(ContinueStmt* E) {
+void VisitContinueStmt(const ContinueStmt* E) {
   ContinueLoc = E->getContinueLoc();
 }
 
-void VisitBreakStmt(BreakStmt* E) {
-  BreakLoc = E->getBreakLoc();
+void VisitBreakStmt(const BreakStmt* E) {
+  if (!InSwitch)
+BreakLoc = E->getBreakLoc();
+}
+
+void VisitSwitchStmt(const SwitchStmt* S) {
+  if (const Stmt *Init = S->getInit())
+Visit(Init);
+  if (const Stmt *CondVar = S->getConditionVariableDeclStmt())
+Visit(CondVar);
+  if (const Stmt *Cond = S->getCond())
+Visit(Cond);
+
+  // Don't return break statements from the body of a switch.
+  InSwitch = true;
+  if (const Stmt *Body = S->getBody())
+Visit(Body);
+  InSwitch = false;
+}
+
+void VisitForStmt(const ForStmt *S) {
+  // Only visit the init statement of a for loop; the body
+  // has a different break/continue scope.
+  if (const Stmt *Init = S->getInit())
+Visit(Init);
+}
+
+void VisitWhileStmt(const WhileStmt *) {
+  // Do nothing; the children of a while loop have a different
+  // break/continue scope.
+}
+
+void VisitDoStmt(const DoStmt *) {
+  // Do nothing; the children of a while loop have a different
+  // break/continue scope.
+}
+
+void VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
+  // Only visit the initialization of a for loop; the body
+  // has 

Re: [PATCH] D34563: [ubsan] Disable the object-size check at -O0

2017-06-23 Thread Justin Bogner via cfe-commits
Vedant Kumar via Phabricator  writes:
> vsk created this revision.
>
> This is motivated by the thread:
> [cfe-dev] Disabling ubsan's object size check at -O0
>
> I think the driver is the best place to disable a sanitizer check at
> particular optimization levels. Doing so in the frontend is messy, and
> makes it really hard to test IR generation for the check. Making the
> change in CodeGen has the same issues.
>
>
> https://reviews.llvm.org/D34563
>
> Files:
>   lib/Driver/SanitizerArgs.cpp
>   test/Driver/fsanitize-object-size.c
>   test/Driver/fsanitize.c
>
> Index: test/Driver/fsanitize.c
> ===
> --- test/Driver/fsanitize.c
> +++ test/Driver/fsanitize.c
> @@ -3,27 +3,27 @@
>  // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined 
> -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-UNDEFINED-TRAP
>  // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap 
> -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-UNDEFINED-TRAP
>  // RUN: %clang -target x86_64-linux-gnu -fsanitize-undefined-trap-on-error 
> -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-UNDEFINED-TRAP
> -// CHECK-UNDEFINED-TRAP: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){19}"}}
> -// CHECK-UNDEFINED-TRAP: 
> "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
> -// CHECK-UNDEFINED-TRAP2: 
> "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
> +// CHECK-UNDEFINED-TRAP: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}}
> +// CHECK-UNDEFINED-TRAP: 
> "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
> +// CHECK-UNDEFINED-TRAP2: 
> "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
>  
>  // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | 
> FileCheck %s --check-prefix=CHECK-UNDEFINED
> -// CHECK-UNDEFINED: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){20}"}}
> +// CHECK-UNDEFINED: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
>  
>  // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
> -// CHECK-UNDEFINED-DARWIN: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
> +// CHECK-UNDEFINED-DARWIN: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
>  
>  // RUN: %clang -target i386-unknown-openbsd -fsanitize=undefined %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-OPENBSD
> -// CHECK-UNDEFINED-OPENBSD: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|re

Two builders are off-line for maintenance

2017-06-23 Thread Galina Kistanova via cfe-commits
Hello everyone,

I took builders llvm-clang-x86_64-expensive-checks-win and
llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast off-line for maintenance.

Thank you for understanding.

Thanks

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


[PATCH] D34563: [ubsan] Disable the object-size check at -O0

2017-06-23 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

This is motivated by the thread:
[cfe-dev] Disabling ubsan's object size check at -O0

I think the driver is the best place to disable a sanitizer check at particular 
optimization levels. Doing so in the frontend is messy, and makes it really 
hard to test IR generation for the check. Making the change in CodeGen has the 
same issues.


https://reviews.llvm.org/D34563

Files:
  lib/Driver/SanitizerArgs.cpp
  test/Driver/fsanitize-object-size.c
  test/Driver/fsanitize.c

Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -3,27 +3,27 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize-undefined-trap-on-error -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
-// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){19}"}}
-// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
-// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
+// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}}
+// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
+// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED
-// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){20}"}}
+// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
 
 // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
-// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
+// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
 
 // RUN: %clang -target i386-unknown-openbsd -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-OPENBSD
-// CHECK-UNDEFINED-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
+// CHECK-UNDEFINED-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-bas

[PATCH] D34562: [MSP430] Fix data layout string.

2017-06-23 Thread Vadzim Dambrouski via Phabricator via cfe-commits
pftbest added a comment.

Thanks!

> shall we support only EABI or... 2 different ABIs?

GCC supports only EABI, and i think we should also spend our limited resources 
on more important issues, than supporting old abi.


https://reviews.llvm.org/D34562



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


r306137 - [MS] Don't statically initialize dllimport member function pointers

2017-06-23 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Jun 23 13:29:13 2017
New Revision: 306137

URL: http://llvm.org/viewvc/llvm-project?rev=306137&view=rev
Log:
[MS] Don't statically initialize dllimport member function pointers

We were already applying the same rules to dllimport function pointers.
David Majnemer added that logic back in r211677 to fix PR20130.  We
failed to extend that logic to non-virtual member function pointers,
which are basically function pointers in a struct with some extra
offsets.

Fixes PR33570.

Added:
cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=306137&r1=306136&r2=306137&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Jun 23 13:29:13 2017
@@ -1665,6 +1665,19 @@ static bool CheckLValueConstantExpressio
   return true;
 }
 
+/// Member pointers are constant expressions unless they point to a
+/// non-virtual dllimport member function.
+static bool CheckMemberPointerConstantExpression(EvalInfo &Info,
+ SourceLocation Loc,
+ QualType Type,
+ const APValue &Value) {
+  const ValueDecl *Member = Value.getMemberPointerDecl();
+  const auto *FD = dyn_cast_or_null(Member);
+  if (!FD)
+return true;
+  return FD->isVirtual() || !FD->hasAttr();
+}
+
 /// Check that this core constant expression is of literal type, and if not,
 /// produce an appropriate diagnostic.
 static bool CheckLiteralType(EvalInfo &Info, const Expr *E,
@@ -1757,6 +1770,9 @@ static bool CheckConstantExpression(Eval
 return CheckLValueConstantExpression(Info, DiagLoc, Type, LVal);
   }
 
+  if (Value.isMemberPointer())
+return CheckMemberPointerConstantExpression(Info, DiagLoc, Type, Value);
+
   // Everything else is fine.
   return true;
 }

Added: cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp?rev=306137&view=auto
==
--- cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/dllimport-memptr-global.cpp Fri Jun 23 13:29:13 
2017
@@ -0,0 +1,58 @@
+// Also check that -Wglobal-constructors does the right thing. Strictly
+// speaking, this is a Sema test, but this avoids test case duplication.
+// RUN: %clang_cc1 -Wglobal-constructors %s -verify -triple i686-windows-msvc 
-fms-extensions -std=c++11
+//
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple i686-windows-msvc 
-fms-extensions -std=c++11 | FileCheck %s
+
+struct __declspec(dllimport) Single {
+  void nonvirt();
+  virtual void virt();
+};
+
+struct A { int a; };
+struct B { int b; };
+struct __declspec(dllimport) Multi : A, B {
+  void nonvirt();
+  virtual void virt();
+};
+
+struct __declspec(dllimport) Virtual : virtual A {
+  void nonvirt();
+  virtual void virt();
+};
+
+struct General;
+static_assert(sizeof(void (General::*)()) == 16, "force general memptr model");
+struct __declspec(dllimport) General {
+  void nonvirt();
+  virtual void virt();
+};
+
+auto mp_single_nv = &Single::nonvirt; // expected-warning {{global 
constructor}}
+auto mp_multi_nv = &Multi::nonvirt; // expected-warning {{global constructor}}
+auto mp_virtual_nv = &Virtual::nonvirt; // expected-warning {{global 
constructor}}
+auto mp_general_nv = &General::nonvirt; // expected-warning {{global 
constructor}}
+
+auto mp_single_v = &Single::virt;
+auto mp_multi_v = &Multi::virt;
+auto mp_virtual_v = &Virtual::virt;
+auto mp_general_v = &General::virt;
+
+// All of the non-virtual globals need dynamic initializers.
+
+// CHECK: @"\01?mp_single_nv@@3P8Single@@AEXXZQ1@" = global i8* null, align 4
+// CHECK: @"\01?mp_multi_nv@@3P8Multi@@AEXXZQ1@" = global { i8*, i32 } 
zeroinitializer, align 4
+// CHECK: @"\01?mp_virtual_nv@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 
} zeroinitializer, align 4
+// CHECK: @"\01?mp_general_nv@@3P8General@@AEXXZQ1@" = global { i8*, i32, i32, 
i32 } zeroinitializer, align 4
+
+// CHECK: @"\01?mp_single_v@@3P8Single@@AEXXZQ1@" = global i8* bitcast (void 
(%struct.Single*, ...)* @"\01??_9Single@@$BA@AE" to i8*), align 4
+// CHECK: @"\01?mp_multi_v@@3P8Multi@@AEXXZQ1@" = global { i8*, i32 } { i8* 
bitcast (void (%struct.Multi*, ...)* @"\01??_9Multi@@$BA@AE" to i8*), i32 0 }, 
align 4
+// CHECK: @"\01?mp_virtual_v@@3P8Virtual@@AEXXZQ1@" = global { i8*, i32, i32 } 
{ i8* bitcast (void (%struct.Virtual*, ...)* @"\01??_9Virtual@@$BA@AE" to i8*), 
i32 0, i32 0 }, align 4
+// CHECK: @"\01?mp_general_v@@3P8General@@AEXXZQ1@" = global { i8*, i32, i32, 
i32 } { i8* bitcast (void (%struct.General*, ...)* @"\01??_9Gen

[PATCH] D34562: [MSP430] Fix data layout string.

2017-06-23 Thread Anton Korobeynikov via Phabricator via cfe-commits
asl added a comment.

Meta-question: shall we support only EABI or... 2 different ABIs? It seems it 
does not make any sense to support anything besides EABI.


https://reviews.llvm.org/D34562



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


[PATCH] D34562: [MSP430] Fix data layout string.

2017-06-23 Thread Vadzim Dambrouski via Phabricator via cfe-commits
pftbest created this revision.

Change data layout string so it would be compatible with MSP430 EABI.

Depends on https://reviews.llvm.org/D34561


https://reviews.llvm.org/D34562

Files:
  lib/Basic/Targets.cpp
  test/CodeGen/target-data.c


Index: test/CodeGen/target-data.c
===
--- test/CodeGen/target-data.c
+++ test/CodeGen/target-data.c
@@ -175,7 +175,7 @@
 
 // RUN: %clang_cc1 -triple msp430-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=MSP430
-// MSP430: target datalayout = "e-m:e-p:16:16-i32:16:32-a:16-n8:16"
+// MSP430: target datalayout = 
"e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"
 
 // RUN: %clang_cc1 -triple tce-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=TCE
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -7503,7 +7503,7 @@
 IntPtrType = SignedInt;
 PtrDiffType = SignedInt;
 SigAtomicType = SignedLong;
-resetDataLayout("e-m:e-p:16:16-i32:16:32-a:16-n8:16");
+resetDataLayout("e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16");
   }
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {


Index: test/CodeGen/target-data.c
===
--- test/CodeGen/target-data.c
+++ test/CodeGen/target-data.c
@@ -175,7 +175,7 @@
 
 // RUN: %clang_cc1 -triple msp430-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=MSP430
-// MSP430: target datalayout = "e-m:e-p:16:16-i32:16:32-a:16-n8:16"
+// MSP430: target datalayout = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"
 
 // RUN: %clang_cc1 -triple tce-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=TCE
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -7503,7 +7503,7 @@
 IntPtrType = SignedInt;
 PtrDiffType = SignedInt;
 SigAtomicType = SignedLong;
-resetDataLayout("e-m:e-p:16:16-i32:16:32-a:16-n8:16");
+resetDataLayout("e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16");
   }
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r306127 - [GSoC] Add support for CC1 options.

2017-06-23 Thread Yuka Takahashi via cfe-commits
Author: yamaguchi
Date: Fri Jun 23 12:05:50 2017
New Revision: 306127

URL: http://llvm.org/viewvc/llvm-project?rev=306127&view=rev
Log:
[GSoC] Add support for CC1 options.

Summary:
Add value completion support for options which are defined in
CC1Options.td, because we only handled options in Options.td.

Reviewers: ruiu, v.g.vassilev, teemperor

Subscribers: llvm-commits

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

Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/test/Driver/autocomplete.c

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=306127&r1=306126&r2=306127&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Jun 23 12:05:50 2017
@@ -158,7 +158,7 @@ def msave_temp_labels : Flag<["-"], "msa
"Note this may change .s semantics and shouldn't generally be used "
"on compiler-generated code.">;
 def mrelocation_model : Separate<["-"], "mrelocation-model">,
-  HelpText<"The relocation model to use">;
+  HelpText<"The relocation model to use">, 
Values<"static,pic,ropi,rwpi,ropi-rwpi,dynamic-no-pic">;
 def fno_math_builtin : Flag<["-"], "fno-math-builtin">,
   HelpText<"Disable implicit builtin knowledge of math functions">;
 }
@@ -229,7 +229,7 @@ def no_struct_path_tbaa : Flag<["-"], "n
 def masm_verbose : Flag<["-"], "masm-verbose">,
   HelpText<"Generate verbose assembly output">;
 def mcode_model : Separate<["-"], "mcode-model">,
-  HelpText<"The code model to use">;
+  HelpText<"The code model to use">, Values<"small,kernel,medium,large">;
 def mdebug_pass : Separate<["-"], "mdebug-pass">,
   HelpText<"Enable additional debug output">;
 def mdisable_fp_elim : Flag<["-"], "mdisable-fp-elim">,
@@ -308,7 +308,7 @@ def fsanitize_coverage_no_prune
   HelpText<"Disable coverage pruning (i.e. instrument all blocks/edges)">;
 def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">,
 HelpText<"Enable PGO instrumentation. The accepted value is clang, llvm, "
- "or none">;
+ "or none">, Values<"none,clang,llvm">;
 def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">,
 HelpText<"Generate instrumented code to collect execution counts into "
  " (overridden by LLVM_PROFILE_FILE env var)">;
@@ -348,9 +348,9 @@ def diagnostic_serialized_file : Separat
   HelpText<"File for serializing diagnostics in a binary format">;
 
 def fdiagnostics_format : Separate<["-"], "fdiagnostics-format">,
-  HelpText<"Change diagnostic formatting to match IDE and command line tools">;
+  HelpText<"Change diagnostic formatting to match IDE and command line 
tools">, Values<"clang,msvc,msvc-fallback,vi">;
 def fdiagnostics_show_category : Separate<["-"], "fdiagnostics-show-category">,
-  HelpText<"Print diagnostic category">;
+  HelpText<"Print diagnostic category">, Values<"none,id,name">;
 def fno_diagnostics_use_presumed_location : Flag<["-"], 
"fno-diagnostics-use-presumed-location">,
   HelpText<"Ignore #line directives when displaying diagnostic locations">;
 def ftabstop : Separate<["-"], "ftabstop">, MetaVarName<"">,
@@ -595,11 +595,11 @@ def fconstant_string_class : Separate<["
   MetaVarName<"">,
   HelpText<"Specify the class to use for constant Objective-C string 
objects.">;
 def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">,
-  HelpText<"Objective-C++ Automatic Reference Counting standard library kind">;
+  HelpText<"Objective-C++ Automatic Reference Counting standard library 
kind">, Values<"libc++,libstdc++,none">;
 def fobjc_runtime_has_weak : Flag<["-"], "fobjc-runtime-has-weak">,
   HelpText<"The target Objective-C runtime supports ARC weak operations">;
 def fobjc_dispatch_method_EQ : Joined<["-"], "fobjc-dispatch-method=">,
-  HelpText<"Objective-C dispatch method to use">;
+  HelpText<"Objective-C dispatch method to use">, 
Values<"legacy,non-legacy,mixed">;
 def disable_objc_default_synthesize_properties : Flag<["-"], 
"disable-objc-default-synthesize-properties">,
   HelpText<"disable the default synthesis of Objective-C properties">;
 def fencode_extended_block_signature : Flag<["-"], 
"fencode-extended-block-signature">,
@@ -673,7 +673,7 @@ def fnative_half_arguments_and_returns :
 def fallow_half_arguments_and_returns : Flag<["-"], 
"fallow-half-arguments-and-returns">,
   HelpText<"Allow function arguments and returns of type half">;
 def fdefault_calling_conv_EQ : Joined<["-"], "fdefault-calling-conv=">,
-  HelpText<"Set default MS calling convention">;
+  HelpText<"Set default MS calling convention">, 
Values<"cdecl,fastcall,stdcall,vectorcall">;
 def finclude_default_header : Flag<["-"], "finclude-default-header">,
   HelpText<"Include the default header file for OpenCL">;
 def fpreserve_vec3_type : Flag<["-"], "f

r306126 - Add a ThinLTO cache policy for controlling the maximum cache size in bytes.

2017-06-23 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Jun 23 12:05:03 2017
New Revision: 306126

URL: http://llvm.org/viewvc/llvm-project?rev=306126&view=rev
Log:
Add a ThinLTO cache policy for controlling the maximum cache size in bytes.

This is useful when an upper limit on the cache size needs to be
controlled independently of the amount of the amount of free space.

One use case is a machine with a large number of cache directories
(e.g. a buildbot slave hosting a large number of independent build
jobs). By imposing an upper size limit on each cache directory,
users can more easily estimate the server's capacity.

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

Modified:
cfe/trunk/docs/ThinLTO.rst

Modified: cfe/trunk/docs/ThinLTO.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ThinLTO.rst?rev=306126&r1=306125&r2=306126&view=diff
==
--- cfe/trunk/docs/ThinLTO.rst (original)
+++ cfe/trunk/docs/ThinLTO.rst Fri Jun 23 12:05:03 2017
@@ -146,6 +146,18 @@ Possible key-value pairs are:
   disk space. A value over 100 is invalid. A value of 0 disables the percentage
   size-based pruning. The default is 75%.
 
+- ``cache_size_bytes=X``, ``cache_size_bytes=Xk``, ``cache_size_bytes=Xm``,
+  ``cache_size_bytes=Xg``:
+  Sets the maximum size for the cache directory to ``X`` bytes (or KB, MB,
+  GB respectively). A value over the amount of available space on the disk
+  will be reduced to the amount of available space. A value of 0 disables
+  the byte size-based pruning. The default is no byte size-based pruning.
+
+  Note that ThinLTO will apply both size-based pruning policies simultaneously,
+  and changing one does not affect the other. For example, a policy of
+  ``cache_size_bytes=1g`` on its own will cause both the 1GB and default 75%
+  policies to be applied unless the default ``cache_size`` is overridden.
+
 - ``prune_after=Xs``, ``prune_after=Xm``, ``prune_after=Xh``: Sets the
   expiration time for cache files to ``X`` seconds (or minutes, hours
   respectively).  When a file hasn't been accessed for ``prune_after`` seconds,


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


[PATCH] D34546: docs: Add documentation for the ThinLTO cache pruning policy string.

2017-06-23 Thread Peter Collingbourne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306125: docs: Add documentation for the ThinLTO cache 
pruning policy string. (authored by pcc).

Changed prior to commit:
  https://reviews.llvm.org/D34546?vs=103682&id=103743#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34546

Files:
  cfe/trunk/docs/ThinLTO.rst


Index: cfe/trunk/docs/ThinLTO.rst
===
--- cfe/trunk/docs/ThinLTO.rst
+++ cfe/trunk/docs/ThinLTO.rst
@@ -126,6 +126,38 @@
 - lld (as of LLVM r296702):
   ``-Wl,--thinlto-cache-dir=/path/to/cache``
 
+Cache Pruning
+-
+
+To help keep the size of the cache under control, ThinLTO supports cache
+pruning. Cache pruning is supported with ld64 and ELF lld, but currently only
+ELF lld allows you to control the policy with a policy string.  The cache
+policy must be specified with a linker option.
+
+- ELF lld (as of LLVM r298036):
+  ``-Wl,--thinlto-cache-policy,POLICY``
+
+A policy string is a series of key-value pairs separated by ``:`` characters.
+Possible key-value pairs are:
+
+- ``cache_size=X%``: The maximum size for the cache directory is ``X`` percent
+  of the available space on the the disk. Set to 100 to indicate no limit,
+  50 to indicate that the cache size will not be left over half the available
+  disk space. A value over 100 is invalid. A value of 0 disables the percentage
+  size-based pruning. The default is 75%.
+
+- ``prune_after=Xs``, ``prune_after=Xm``, ``prune_after=Xh``: Sets the
+  expiration time for cache files to ``X`` seconds (or minutes, hours
+  respectively).  When a file hasn't been accessed for ``prune_after`` seconds,
+  it is removed from the cache. A value of 0 disables the expiration-based
+  pruning. The default is 1 week.
+
+- ``prune_interval=Xs``, ``prune_interval=Xm``, ``prune_interval=Xh``:
+  Sets the pruning interval to ``X`` seconds (or minutes, hours
+  respectively). This is intended to be used to avoid scanning the directory
+  too often. It does not impact the decision of which files to prune. A
+  value of 0 forces the scan to occur. The default is every 20 minutes.
+
 Clang Bootstrap
 ---
 


Index: cfe/trunk/docs/ThinLTO.rst
===
--- cfe/trunk/docs/ThinLTO.rst
+++ cfe/trunk/docs/ThinLTO.rst
@@ -126,6 +126,38 @@
 - lld (as of LLVM r296702):
   ``-Wl,--thinlto-cache-dir=/path/to/cache``
 
+Cache Pruning
+-
+
+To help keep the size of the cache under control, ThinLTO supports cache
+pruning. Cache pruning is supported with ld64 and ELF lld, but currently only
+ELF lld allows you to control the policy with a policy string.  The cache
+policy must be specified with a linker option.
+
+- ELF lld (as of LLVM r298036):
+  ``-Wl,--thinlto-cache-policy,POLICY``
+
+A policy string is a series of key-value pairs separated by ``:`` characters.
+Possible key-value pairs are:
+
+- ``cache_size=X%``: The maximum size for the cache directory is ``X`` percent
+  of the available space on the the disk. Set to 100 to indicate no limit,
+  50 to indicate that the cache size will not be left over half the available
+  disk space. A value over 100 is invalid. A value of 0 disables the percentage
+  size-based pruning. The default is 75%.
+
+- ``prune_after=Xs``, ``prune_after=Xm``, ``prune_after=Xh``: Sets the
+  expiration time for cache files to ``X`` seconds (or minutes, hours
+  respectively).  When a file hasn't been accessed for ``prune_after`` seconds,
+  it is removed from the cache. A value of 0 disables the expiration-based
+  pruning. The default is 1 week.
+
+- ``prune_interval=Xs``, ``prune_interval=Xm``, ``prune_interval=Xh``:
+  Sets the pruning interval to ``X`` seconds (or minutes, hours
+  respectively). This is intended to be used to avoid scanning the directory
+  too often. It does not impact the decision of which files to prune. A
+  value of 0 forces the scan to occur. The default is every 20 minutes.
+
 Clang Bootstrap
 ---
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r306125 - docs: Add documentation for the ThinLTO cache pruning policy string.

2017-06-23 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Fri Jun 23 11:56:27 2017
New Revision: 306125

URL: http://llvm.org/viewvc/llvm-project?rev=306125&view=rev
Log:
docs: Add documentation for the ThinLTO cache pruning policy string.

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

Modified:
cfe/trunk/docs/ThinLTO.rst

Modified: cfe/trunk/docs/ThinLTO.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ThinLTO.rst?rev=306125&r1=306124&r2=306125&view=diff
==
--- cfe/trunk/docs/ThinLTO.rst (original)
+++ cfe/trunk/docs/ThinLTO.rst Fri Jun 23 11:56:27 2017
@@ -126,6 +126,38 @@ which currently must be enabled through
 - lld (as of LLVM r296702):
   ``-Wl,--thinlto-cache-dir=/path/to/cache``
 
+Cache Pruning
+-
+
+To help keep the size of the cache under control, ThinLTO supports cache
+pruning. Cache pruning is supported with ld64 and ELF lld, but currently only
+ELF lld allows you to control the policy with a policy string.  The cache
+policy must be specified with a linker option.
+
+- ELF lld (as of LLVM r298036):
+  ``-Wl,--thinlto-cache-policy,POLICY``
+
+A policy string is a series of key-value pairs separated by ``:`` characters.
+Possible key-value pairs are:
+
+- ``cache_size=X%``: The maximum size for the cache directory is ``X`` percent
+  of the available space on the the disk. Set to 100 to indicate no limit,
+  50 to indicate that the cache size will not be left over half the available
+  disk space. A value over 100 is invalid. A value of 0 disables the percentage
+  size-based pruning. The default is 75%.
+
+- ``prune_after=Xs``, ``prune_after=Xm``, ``prune_after=Xh``: Sets the
+  expiration time for cache files to ``X`` seconds (or minutes, hours
+  respectively).  When a file hasn't been accessed for ``prune_after`` seconds,
+  it is removed from the cache. A value of 0 disables the expiration-based
+  pruning. The default is 1 week.
+
+- ``prune_interval=Xs``, ``prune_interval=Xm``, ``prune_interval=Xh``:
+  Sets the pruning interval to ``X`` seconds (or minutes, hours
+  respectively). This is intended to be used to avoid scanning the directory
+  too often. It does not impact the decision of which files to prune. A
+  value of 0 forces the scan to occur. The default is every 20 minutes.
+
 Clang Bootstrap
 ---
 


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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-23 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:730
+
+Mapping TreeComparator::matchTopDown() const {
+  PriorityList L1(T1);

arphaman wrote:
> Johannes, it seems to me that your implementation of the top-down portion of 
> the GumTree algorithm doesn't use the `an empty list A of candidate mappings` 
> that's described in the paper (and that you have in the Python prototype). Is 
> that correct or am I missing something?
Yes, initially I implemented it as it is described in the paper, but then I 
realized that the list of candidate mappings will always stay empty, because 
the condition in the top-down algorithm in the paper on line 14 will never be 
true. Maybe I am mistaken here, but if `t1` and `t2` are isomorphic, then none 
of the descendants of `t1` will be isomorphic to `t2`. I mean, the height of 
isomorphic trees must be equal, and the descendant does not have the same 
height. So to me this looks like an error in the paper, I probably should have 
communicated this.
What I did instead is, I had a look at the reference implementation, and what 
they do instead of using a list of candidate mappings is to just use a data 
structure for the mapping that allows multiple matches for each node.
After matching collecting all candidates this way, they extract the unambiguous 
matches and then sort the ambiguous matches by their parents' similarity.
[[ 
https://github.com/GumTreeDiff/gumtree/blob/develop/core/src/main/java/com/github/gumtreediff/matchers/heuristic/gt/AbstractSubtreeMatcher.java
 | AbstractSubtreeMatcher.java ]]
[[ 
https://github.com/GumTreeDiff/gumtree/blob/develop/core/src/main/java/com/github/gumtreediff/matchers/heuristic/gt/GreedySubtreeMatcher.java
 | GreedySubtreeMatcher.java ]]
This seems to be a good solution,  I plan to implement that in the future.


https://reviews.llvm.org/D34329



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


r306123 - test: fix negative test case

2017-06-23 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Fri Jun 23 11:52:49 2017
New Revision: 306123

URL: http://llvm.org/viewvc/llvm-project?rev=306123&view=rev
Log:
test: fix negative test case

Add missing -### to the driver to ensure that we dont try to run the
actual command.  The host may not support the IAS.  Should fix the SCEI
buildbots.

Modified:
cfe/trunk/test/Driver/nozlibcompress.c

Modified: cfe/trunk/test/Driver/nozlibcompress.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/nozlibcompress.c?rev=306123&r1=306122&r2=306123&view=diff
==
--- cfe/trunk/test/Driver/nozlibcompress.c (original)
+++ cfe/trunk/test/Driver/nozlibcompress.c Fri Jun 23 11:52:49 2017
@@ -1,7 +1,7 @@
 // REQUIRES: nozlib
 
-// RUN: %clang -fintegrated-as -gz -c %s 2>&1 | FileCheck %s -check-prefix 
CHECK-WARN
-// RUN: %clang -fintegrated-as -gz=none -c %s 2>&1 | FileCheck -allow-empty 
-check-prefix CHECK-NOWARN %s
+// RUN: %clang -### -fintegrated-as -gz -c %s 2>&1 | FileCheck %s 
-check-prefix CHECK-WARN
+// RUN: %clang -### -fintegrated-as -gz=none -c %s 2>&1 | FileCheck 
-allow-empty -check-prefix CHECK-NOWARN %s
 
 // CHECK-WARN: warning: cannot compress debug sections (zlib not installed)
 // CHECK-NOWARN-NOT: warning: cannot compress debug sections (zlib not 
installed)


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


[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

2017-06-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Fair enough. LGTM from my side.


https://reviews.llvm.org/D34299



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


[PATCH] D34556: [libcxx] Annotate c++17 aligned new/delete operators with availability attribute

2017-06-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: 
test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp:12-16
+// test availability of new/delete operators introduced in c++17.
+
+#ifdef __APPLE__
+#undef _LIBCPP_DISABLE_AVAILABILITY
+#endif

There is a lit configuration to choose whether to run with availability or not. 
 We should just mark the test unsupported when we don't want it to run.

It's also important to run the rest of the suite with availability turned on, 
to see which other tests start to fail.



Comment at: 
test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp:21-26
+#ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
+  int *p0 = new ((std::align_val_t)16) int(1);
+  (void)p0;
+  int *p1 = new ((std::align_val_t)16) int[1];
+  (void)p1;
+#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101300

Similarly here, we can just mark the test unsupported when we don't have 
availability turned on or we're targeting 10.13 or later.


https://reviews.llvm.org/D34556



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


[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

2017-06-23 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In https://reviews.llvm.org/D34299#788908, @arphaman wrote:

> Ok, so now the null check `return.sloc.load` won't call the checker in 
> compiler-rt and so the program won't `abort` and won't hit the `unreachable`. 
> I have one question tough:
>
> This patch changes the behavior of this sanitizer for the example that I gave 
> above.


Yes, in the case where there is no explicit return, and the return value 
happens to be null.

> Previously a runtime diagnostic was emitted, but now there is none. While I'm 
> not saying that the previous behaviour was correct, I'm wondering if the new 
> behaviour is right.  I think that for C++ it makes sense, but I don't know 
> the right answer for C. I'm leaning more towards the new behaviour, since 
> technically in C falling off without returning a value is not UB unless that 
> return value is used by the caller. But at the same time, since we don't 
> diagnose `return` UB for C, maybe it's still worth diagnosing this particular 
> issue? The user might not catch it otherwise at all (or they might catch it 
> later when they try to access it, but by that point they might not know where 
> the pointer came from). WDYT?

Without seeing what the caller does with the result, the return value check 
can't do a good job of diagnosing missing returns. I think clang should emit a 
diagnostic in the example above, and -Wreturn-type does. So I think the new 
behavior is appropriate.


https://reviews.llvm.org/D34299



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-06-23 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

In https://reviews.llvm.org/D33589#789002, @alexfh wrote:

> why do we want to make an exception for comments and not for regular code?


This is not an exception for comments: the `PenaltyExcessCharacter` is used 
whenever the code is longer than the `ColumnLimit`, and used to compute the 
best solution.
The default value is extremely high, so there is no practical difference: code 
does not go beyond the column, except for specific exceptions.

However, the difference becomes apparent when reducing this penalty: in that 
case, code can break the column limit instead of wrapping, but it does not 
happen with comments. This patch tries to restore the parity, and let comments 
break the comment limit as well.


https://reviews.llvm.org/D33589



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


[PATCH] D34557: Sort the autocomplete candidates before printing them out.

2017-06-23 Thread Rui Ueyama via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306116: Sort the autocomplete candidates before printing 
them out. (authored by ruiu).

Changed prior to commit:
  https://reviews.llvm.org/D34557?vs=103731&id=103733#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34557

Files:
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/test/Driver/autocomplete.c


Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1245,6 +1245,13 @@
   SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg);
 }
 
+// Sort the autocomplete candidates so that shells print them out in a
+// deterministic order. We could sort in any way, but we chose
+// case-insensitive sorting for consistency with the -help option
+// which prints out options in the case-insensitive alphabetical order.
+std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
+  [](StringRef A, StringRef B) { return A.compare_lower(B) < 0; });
+
 llvm::outs() << llvm::join(SuggestedCompletions, " ") << '\n';
 return false;
   }
Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -11,26 +11,26 @@
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
 // RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
-// MEABIALL: default 4 5 gnu
+// MEABIALL: 4 5 default gnu
 // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD
 // CLSTD: CL2.0
 // RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL
 // CLSTDALL: cl CL cl1.1 CL1.1 cl1.2 CL1.2 cl2.0 CL2.0
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s 
-check-prefix=FNOSANICOVER
 // FNOSANICOVER: func
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=, | FileCheck %s 
-check-prefix=FNOSANICOVERALL
-// FNOSANICOVERALL: func bb edge indirect-calls trace-bb trace-cmp trace-div 
trace-gep 8bit-counters trace-pc trace-pc-guard no-prune inline-8bit-counters
+// FNOSANICOVERALL: 8bit-counters bb edge func indirect-calls 
inline-8bit-counters no-prune trace-bb trace-cmp trace-div trace-gep trace-pc 
trace-pc-guard
 // RUN: %clang --autocomplete=-ffp-contract=, | FileCheck %s 
-check-prefix=FFPALL
-// FFPALL: fast on off
+// FFPALL: fast off on
 // RUN: %clang --autocomplete=-flto=, | FileCheck %s -check-prefix=FLTOALL
-// FLTOALL: thin full
+// FLTOALL: full thin
 // RUN: %clang --autocomplete=-fveclib=, | FileCheck %s 
-check-prefix=FVECLIBALL
-// FVECLIBALL: Accelerate SVML none
+// FVECLIBALL: Accelerate none SVML
 // RUN: %clang --autocomplete=-fshow-overloads=, | FileCheck %s 
-check-prefix=FSOVERALL
-// FSOVERALL: best all
+// FSOVERALL: all best
 // RUN: %clang --autocomplete=-fvisibility=, | FileCheck %s 
-check-prefix=FVISIBILITYALL
-// FVISIBILITYALL: hidden default
+// FVISIBILITYALL: default hidden
 // RUN: %clang --autocomplete=-mfloat-abi=, | FileCheck %s 
-check-prefix=MFLOATABIALL
-// MFLOATABIALL: soft softfp hard
+// MFLOATABIALL: hard soft softfp
 // RUN: %clang --autocomplete=-mthread-model, | FileCheck %s 
-check-prefix=MTHREADMODELALL
 // MTHREADMODELALL: posix single


Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1245,6 +1245,13 @@
   SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg);
 }
 
+// Sort the autocomplete candidates so that shells print them out in a
+// deterministic order. We could sort in any way, but we chose
+// case-insensitive sorting for consistency with the -help option
+// which prints out options in the case-insensitive alphabetical order.
+std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
+  [](StringRef A, StringRef B) { return A.compare_lower(B) < 0; });
+
 llvm::outs() << llvm::join(SuggestedCompletions, " ") << '\n';
 return false;
   }
Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -11,26 +11,26 @@
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
 // RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
-// MEABIALL: default 4 5 gnu
+// MEABIALL: 4 5 default gnu
 // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD
 // CLSTD: CL2.0
 // RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL
 // CLSTDALL: cl CL cl1.1 CL1.1 cl1.2 CL1.2 cl2.0 CL2.0
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f

r306116 - Sort the autocomplete candidates before printing them out.

2017-06-23 Thread Rui Ueyama via cfe-commits
Author: ruiu
Date: Fri Jun 23 10:37:52 2017
New Revision: 306116

URL: http://llvm.org/viewvc/llvm-project?rev=306116&view=rev
Log:
Sort the autocomplete candidates before printing them out.

Currently, autocompleted options are displayed in the same order as we
wrote them in .td files. This patch sort them out in clang so that they
are sorted alphabetically. This should improve usability.

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

Modified:
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/test/Driver/autocomplete.c

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=306116&r1=306115&r2=306116&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Jun 23 10:37:52 2017
@@ -1245,6 +1245,13 @@ bool Driver::HandleImmediateArgs(const C
   SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg);
 }
 
+// Sort the autocomplete candidates so that shells print them out in a
+// deterministic order. We could sort in any way, but we chose
+// case-insensitive sorting for consistency with the -help option
+// which prints out options in the case-insensitive alphabetical order.
+std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
+  [](StringRef A, StringRef B) { return A.compare_lower(B) < 0; });
+
 llvm::outs() << llvm::join(SuggestedCompletions, " ") << '\n';
 return false;
   }

Modified: cfe/trunk/test/Driver/autocomplete.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/autocomplete.c?rev=306116&r1=306115&r2=306116&view=diff
==
--- cfe/trunk/test/Driver/autocomplete.c (original)
+++ cfe/trunk/test/Driver/autocomplete.c Fri Jun 23 10:37:52 2017
@@ -11,7 +11,7 @@
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
 // RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
-// MEABIALL: default 4 5 gnu
+// MEABIALL: 4 5 default gnu
 // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD
 // CLSTD: CL2.0
 // RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL
@@ -19,18 +19,18 @@
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s 
-check-prefix=FNOSANICOVER
 // FNOSANICOVER: func
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=, | FileCheck %s 
-check-prefix=FNOSANICOVERALL
-// FNOSANICOVERALL: func bb edge indirect-calls trace-bb trace-cmp trace-div 
trace-gep 8bit-counters trace-pc trace-pc-guard no-prune inline-8bit-counters
+// FNOSANICOVERALL: 8bit-counters bb edge func indirect-calls 
inline-8bit-counters no-prune trace-bb trace-cmp trace-div trace-gep trace-pc 
trace-pc-guard
 // RUN: %clang --autocomplete=-ffp-contract=, | FileCheck %s 
-check-prefix=FFPALL
-// FFPALL: fast on off
+// FFPALL: fast off on
 // RUN: %clang --autocomplete=-flto=, | FileCheck %s -check-prefix=FLTOALL
-// FLTOALL: thin full
+// FLTOALL: full thin
 // RUN: %clang --autocomplete=-fveclib=, | FileCheck %s 
-check-prefix=FVECLIBALL
-// FVECLIBALL: Accelerate SVML none
+// FVECLIBALL: Accelerate none SVML
 // RUN: %clang --autocomplete=-fshow-overloads=, | FileCheck %s 
-check-prefix=FSOVERALL
-// FSOVERALL: best all
+// FSOVERALL: all best
 // RUN: %clang --autocomplete=-fvisibility=, | FileCheck %s 
-check-prefix=FVISIBILITYALL
-// FVISIBILITYALL: hidden default
+// FVISIBILITYALL: default hidden
 // RUN: %clang --autocomplete=-mfloat-abi=, | FileCheck %s 
-check-prefix=MFLOATABIALL
-// MFLOATABIALL: soft softfp hard
+// MFLOATABIALL: hard soft softfp
 // RUN: %clang --autocomplete=-mthread-model, | FileCheck %s 
-check-prefix=MTHREADMODELALL
 // MTHREADMODELALL: posix single


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


[PATCH] D34556: [libcxx] Annotate c++17 aligned new/delete operators with availability attribute

2017-06-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

> I followed the other availability macros in using "strict", but I'm not sure 
> this was the right decision. The documentation seems to recommend not using 
> "strict" (it says that weakly-linking is almost always a better API choice).

libc++ is one of the exceptions.  Use `strict`.


https://reviews.llvm.org/D34556



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


r306115 - Revert "Revert r305164/5/7."

2017-06-23 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Fri Jun 23 10:34:16 2017
New Revision: 306115

URL: http://llvm.org/viewvc/llvm-project?rev=306115&view=rev
Log:
Revert "Revert r305164/5/7."

Restore the `-gz` option to the driver with some minor tweaks to handle
the additional case for `-Wa,--compress-debug-sections`.

This intends to make the compression of the debug information
controllable from the driver.  The following is the behaviour:

  -gz   enable compression (ambiguous for format, will default to 
zlib-gnu)
  -gz=none  disable compression
  -gz=zlib-gnu  enable compression (deprecated GNU style zlib compression)
  -gz=zlib  enable compression (zlib based compression)

Although -Wa,-compress-debug-sections works, it should be discouraged
when using the driver to invoke the assembler.  However, we permit the
assembler to accept the GNU as style argument --compress-debug-sections
to maintain compatibility.

Note, -gz/-gz= does *NOT* imply -g.  That is, you need to additionally
specific -g for debug information to be generated.

Added:
cfe/trunk/test/Driver/compress-noias.c
cfe/trunk/test/Misc/cc1as-compress.s
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/compress.c
cfe/trunk/test/Driver/nozlibcompress.c
cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=306115&r1=306114&r2=306115&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Jun 23 10:34:16 2017
@@ -134,7 +134,6 @@ def migrator_no_finalize_removal : Flag<
 
//===--===//
 
 let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
-
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
 def debug_info_macro : Flag<["-"], "debug-info-macro">,
   HelpText<"Emit macro debug information">;
@@ -144,14 +143,16 @@ def fdebug_compilation_dir : Separate<["
   HelpText<"The compilation directory to embed in the debug info.">;
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">;
+def compress_debug_sections : Flag<["-", "--"], "compress-debug-sections">,
+HelpText<"DWARF debug sections compression">;
+def compress_debug_sections_EQ : Flag<["-"], "compress-debug-sections=">,
+HelpText<"DWARF debug sections compression type">;
 def mno_exec_stack : Flag<["-"], "mnoexecstack">,
   HelpText<"Mark the file as not needing an executable stack">;
 def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
   HelpText<"Make assembler warnings fatal">;
 def mrelax_relocations : Flag<["--"], "mrelax-relocations">,
 HelpText<"Use relaxable elf relocations">;
-def compress_debug_sections : Flag<["-"], "compress-debug-sections">,
-HelpText<"Compress DWARF debug sections using zlib">;
 def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
   HelpText<"Save temporary labels in the symbol table. "
"Note this may change .s semantics and shouldn't generally be used "

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=306115&r1=306114&r2=306115&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Jun 23 10:34:16 2017
@@ -1563,6 +1563,10 @@ def gdwarf_aranges : Flag<["-"], "gdwarf
 def gmodules : Flag <["-"], "gmodules">, Group,
   HelpText<"Generate debug info with external references to clang modules"
" or precompiled headers">;
+def gz : Flag<["-"], "gz">, Group,
+HelpText<"DWARF debug sections compression type">;
+def gz_EQ : Joined<["-"], "gz=">, Group,
+HelpText<"DWARF debug sections compression type">;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,
   HelpText<"Display available options">;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=306115&r1=306114&r2=306115&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Jun 23 10:34:16 2017
@@ -910,6 +910,37 @@ static void RenderDebugEnablingArgs(cons
   }
 }
 
+static void RenderDebugInfoCompressionArgs(const ArgList &Args,
+   

[PATCH] D34557: Sort the autocomplete candidates before printing them out.

2017-06-23 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi accepted this revision.
yamaguchi added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks for the patch.


https://reviews.llvm.org/D34557



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


[PATCH] D34556: [libcxx] Annotate c++17 aligned new/delete operators with availability attribute

2017-06-23 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: 
test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp:35
+  // expected-error@-10 {{call to unavailable function 'operator new[]': 
introduced in macOS 10.13}}
+  // expected-note@new:204 {{candidate function has been explicitly made 
unavailable}}
+  // expected-note@new:188 {{candidate function not viable: no known 
conversion from 'std::align_val_t' to 'const std::nothrow_t' for 2nd argument}}

You probably shouldn't include the line numbers here, it makes the test 
fragile. Ie, do `expected-note@new:*`


https://reviews.llvm.org/D34556



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


[PATCH] D34557: Sort the autocomplete candidates before printing them out.

2017-06-23 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu created this revision.

Currently, autocompleted options are displayed in the same order as we
wrote them in .td files. This patch sort them out in clang so that they
are sorted alphabetically. This should improve usability.


https://reviews.llvm.org/D34557

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -11,26 +11,26 @@
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
 // RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
-// MEABIALL: default 4 5 gnu
+// MEABIALL: 4 5 default gnu
 // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD
 // CLSTD: CL2.0
 // RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL
 // CLSTDALL: cl CL cl1.1 CL1.1 cl1.2 CL1.2 cl2.0 CL2.0
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s 
-check-prefix=FNOSANICOVER
 // FNOSANICOVER: func
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=, | FileCheck %s 
-check-prefix=FNOSANICOVERALL
-// FNOSANICOVERALL: func bb edge indirect-calls trace-bb trace-cmp trace-div 
trace-gep 8bit-counters trace-pc trace-pc-guard no-prune inline-8bit-counters
+// FNOSANICOVERALL: 8bit-counters bb edge func indirect-calls 
inline-8bit-counters no-prune trace-bb trace-cmp trace-div trace-gep trace-pc 
trace-pc-guard
 // RUN: %clang --autocomplete=-ffp-contract=, | FileCheck %s 
-check-prefix=FFPALL
-// FFPALL: fast on off
+// FFPALL: fast off on
 // RUN: %clang --autocomplete=-flto=, | FileCheck %s -check-prefix=FLTOALL
-// FLTOALL: thin full
+// FLTOALL: full thin
 // RUN: %clang --autocomplete=-fveclib=, | FileCheck %s 
-check-prefix=FVECLIBALL
-// FVECLIBALL: Accelerate SVML none
+// FVECLIBALL: Accelerate none SVML
 // RUN: %clang --autocomplete=-fshow-overloads=, | FileCheck %s 
-check-prefix=FSOVERALL
-// FSOVERALL: best all
+// FSOVERALL: all best
 // RUN: %clang --autocomplete=-fvisibility=, | FileCheck %s 
-check-prefix=FVISIBILITYALL
-// FVISIBILITYALL: hidden default
+// FVISIBILITYALL: default hidden
 // RUN: %clang --autocomplete=-mfloat-abi=, | FileCheck %s 
-check-prefix=MFLOATABIALL
-// MFLOATABIALL: soft softfp hard
+// MFLOATABIALL: hard soft softfp
 // RUN: %clang --autocomplete=-mthread-model, | FileCheck %s 
-check-prefix=MTHREADMODELALL
 // MTHREADMODELALL: posix single
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1245,6 +1245,13 @@
   SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg);
 }
 
+// Sort the autocomplete candidates so that shells print them out in a
+// deterministic order. We could sort in any way, but we chose
+// case-insensitive sorting for consistency with the -help option
+// which prints out options in the case-insensitive alphabetical order.
+std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
+  [](StringRef A, StringRef B) { return A.compare_lower(B) < 0; });
+
 llvm::outs() << llvm::join(SuggestedCompletions, " ") << '\n';
 return false;
   }


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -11,26 +11,26 @@
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
 // RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
-// MEABIALL: default 4 5 gnu
+// MEABIALL: 4 5 default gnu
 // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD
 // CLSTD: CL2.0
 // RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL
 // CLSTDALL: cl CL cl1.1 CL1.1 cl1.2 CL1.2 cl2.0 CL2.0
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s -check-prefix=FNOSANICOVER
 // FNOSANICOVER: func
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=, | FileCheck %s -check-prefix=FNOSANICOVERALL
-// FNOSANICOVERALL: func bb edge indirect-calls trace-bb trace-cmp trace-div trace-gep 8bit-counters trace-pc trace-pc-guard no-prune inline-8bit-counters
+// FNOSANICOVERALL: 8bit-counters bb edge func indirect-calls inline-8bit-counters no-prune trace-bb trace-cmp trace-div trace-gep trace-pc trace-pc-guard
 // RUN: %clang --autocomplete=-ffp-contract=, | FileCheck %s -check-prefix=FFPALL
-// FFPALL: fast on off
+// FFPALL: fast off on
 // RUN: %clang --autocomplete=-flto=, | FileCheck %s -check-prefix=FLTOALL
-// FLTOALL: thin full
+// FLTOALL: full thin
 // RUN: %clang --autocomplete=-fveclib=, | FileCheck %s -check-prefix=FVECLIBALL
-// FVECLIBALL: Accelerate SVML none
+// FVECLIBALL: Accelerate none SVML
 // RUN: %clang --autocomplete=-fshow-

[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

I reverted it in r306111 for now.


Repository:
  rL LLVM

https://reviews.llvm.org/D32439



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


r306111 - Revert r306103: "PR26195: Set correct NestedNameSpecifierLoc for the

2017-06-23 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Jun 23 10:10:54 2017
New Revision: 306111

URL: http://llvm.org/viewvc/llvm-project?rev=306111&view=rev
Log:
Revert r306103: "PR26195: Set correct NestedNameSpecifierLoc for the
dependent initializer"

It caused buildbot failures such as this one:
http://bb.pgr.jp/builders/test-clang-msc-x64-on-i686-linux-RA/builds/3777/steps/test_clang/logs/Clang%20%3A%3A%20Index__ctor-init-source-loc.cpp

Removed:
cfe/trunk/test/Index/ctor-init-source-loc.cpp
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=306111&r1=306110&r2=306111&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Jun 23 10:10:54 2017
@@ -3778,15 +3778,6 @@ Sema::BuildMemInitializer(Decl *Construc
   if (BaseType.isNull())
 return true;
 
-  TInfo = Context.CreateTypeSourceInfo(BaseType);
-  DependentNameTypeLoc TL =
-  TInfo->getTypeLoc().castAs();
-  if (!TL.isNull()) {
-TL.setNameLoc(IdLoc);
-TL.setElaboratedKeywordLoc(SourceLocation());
-TL.setQualifierLoc(SS.getWithLocInContext(Context));
-  }
-
   R.clear();
   R.setLookupName(MemberOrBase);
 }

Removed: cfe/trunk/test/Index/ctor-init-source-loc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/ctor-init-source-loc.cpp?rev=306110&view=auto
==
--- cfe/trunk/test/Index/ctor-init-source-loc.cpp (original)
+++ cfe/trunk/test/Index/ctor-init-source-loc.cpp (removed)
@@ -1,117 +0,0 @@
-// RUN: c-index-test -test-load-source all %s | FileCheck %s
-template
-struct Derived:  MyBase::InnerIterator
-{
-Derived() : MyBase::InnerIterator() {}
-// CHECK:  TypeRef=MyBase:2:19 Extent=[5:17 - 5:23]
-};
-
-template
-struct Derived2:  MyBase::Deeper::InnerIterator
-{
-Derived2() : MyBase::Deeper::InnerIterator() {}
-// CHECK:  TypeRef=MyBase:9:19 Extent=[12:18 - 12:24]
-};
-
-template
-struct Templ;
-
-template
-struct Derived3:  Templ::InnerIterator
-{
-Derived3() : Templ::InnerIterator() {}
-// CHECK: TemplateRef=Templ:17:8 Extent=[22:18 - 22:23]
-// CHECK: TypeRef=MyBase:19:19 Extent=[22:24 - 22:30]
-};
-
-
-struct Outer {
-template 
-struct Inner {
-typedef Q Parm;
-};
-};
-
-template
-struct Derived4:  Outer::Inner::Parm
-{
-Derived4() : Outer::Inner::Parm() {}
-// CHECK: TypeRef=struct Outer:28:8 Extent=[38:18 - 38:23]
-// CHECK: TemplateRef=Inner:30:12 Extent=[38:25 - 38:30]
-// CHECK: TypeRef=Q:35:19 Extent=[38:31 - 38:32]
-};
-
-template
-struct Derived5:  Outer::Inner::Parm::InnerIterator
-{
-Derived5() : Outer::Inner::Parm::InnerIterator() {}
-// CHECK: TypeRef=struct Outer:28:8 Extent=[47:18 - 47:23]
-// CHECK: TemplateRef=Inner:30:12 Extent=[47:25 - 47:30]
-// CHECK: TypeRef=Q:44:19 Extent=[47:31 - 47:32]
-};
-
-template
-struct Derived6:  Outer::Inner
-{
-Derived6() : Outer::Inner() {}
-// CHECK: TypeRef=struct Outer:28:8 Extent=[56:18 - 56:23]
-// CHECK: TemplateRef=Inner:30:12 Extent=[56:25 - 56:30]
-// CHECK: TypeRef=Q:53:19 Extent=[56:31 - 56:32]
-};
-
-struct Base {};
-
-struct Derived7:  Outer::Inner::Parm
-{
-Derived7() : Outer::Inner::Parm() {}
-// CHECK: TypeRef=struct Outer:28:8 Extent=[66:18 - 66:23]
-// CHECK: TemplateRef=Inner:30:12 Extent=[66:25 - 66:30]
-// CHECK: TypeRef=struct Base:62:8 Extent=[66:31 - 66:35]
-};
-
-struct Derived8:  Outer::Inner
-{
-Derived8() : Outer::Inner() {}
-// CHECK: TypeRef=struct Outer:28:8 Extent=[74:18 - 74:23]
-// CHECK: TemplateRef=Inner:30:12 Extent=[74:25 - 74:30]
-// CHECK: TypeRef=struct Base:62:8 Extent=[74:31 - 74:35]
-};
-
-namespace Namespace {
-template struct Templ;
-
-struct Outer {
-template 
-struct Inner {
-typedef Q Parm;
-};
-};
-}
-
-template
-struct Derived9:  Namespace::Templ::InnerIterator
-{
-Derived9() : Namespace::Templ::InnerIterator() {}
-// CHECK: NamespaceRef=Namespace:80:11 Extent=[94:18 - 94:27]
-// CHECK: TemplateRef=Templ:81:33 Extent=[94:29 - 94:34]
-// CHECK: TypeRef=MyBase:91:19 Extent=[94:35 - 94:41]
-};
-
-template
-struct Derived10:  Namespace::Templ
-{
-Derived10() : Namespace::Templ() {}
-// CHECK: NamespaceRef=Namespace:80:11 Extent=[103:19 - 103:28]
-// CHECK: TemplateRef=Templ:81:33 Extent=[103:30 - 103:35]
-// CHECK: TypeRef=MyBase:100:19 Extent=[103:36 - 103:42]
-};
-
-template
-struct Derived11:  Namespace::Outer::Inner::Parm
-{
-Derived11() : Namespace::Outer::Inner::Parm() {}
-// CHECK: NamespaceRef=Namespace:80:11 Extent=[112:19 - 112:28]
-// CHECK: TypeRef=struct Namespace::Outer:83:12 Extent=[112:30 - 112:35]
-// CHECK: TemplateRef=Inner:85:16 Extent=[112:37 - 112:42]
-// CHECK: TypeRef=MyBase:109

[PATCH] D34556: [libcxx] Annotate c++17 aligned new/delete operators with availability attribute

2017-06-23 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.

This is needed because older versions of libc++ do not have these operators. If 
users target an older deployment target and try to compile programs in which 
these operators are explicitly called, the compiler will complain.

The following is the list of minimum deployment targets for the four OSes:

macosx: 10.13
ios: 11.0
tvos: 11.0
watchos: 4.0

I followed the other availability macros in using "strict", but I'm not sure 
this was the right decision. The documentation seems to recommend not using 
"strict" (it says that weakly-linking is almost always a better API choice).

rdar://problem/32664169


https://reviews.llvm.org/D34556

Files:
  include/__config
  include/new
  
test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp

Index: test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp
===
--- /dev/null
+++ test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp
@@ -0,0 +1,47 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+// test availability of new/delete operators introduced in c++17.
+
+#ifdef __APPLE__
+#undef _LIBCPP_DISABLE_AVAILABILITY
+#endif
+
+#include 
+
+int main () {
+#ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
+  int *p0 = new ((std::align_val_t)16) int(1);
+  (void)p0;
+  int *p1 = new ((std::align_val_t)16) int[1];
+  (void)p1;
+#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101300
+  // expected-error@-5 {{call to unavailable function 'operator new': introduced in macOS 10.13}}
+  // expected-note@new:196 {{candidate function has been explicitly made unavailable}}
+  // expected-note@new:180 {{candidate function not viable: no known conversion from 'std::align_val_t' to 'const std::nothrow_t' for 2nd argument}}
+  // expected-note@new:213 {{candidate function not viable: no known conversion from 'std::align_val_t' to 'void *' for 2nd argument}}
+  // expected-note@new:179 {{candidate function not viable: requires single argument '__sz', but 2 arguments were provided}}
+  // expected-note@new:197 {{candidate function not viable: requires 3 arguments, but 2 were provided}}
+
+  // expected-error@-10 {{call to unavailable function 'operator new[]': introduced in macOS 10.13}}
+  // expected-note@new:204 {{candidate function has been explicitly made unavailable}}
+  // expected-note@new:188 {{candidate function not viable: no known conversion from 'std::align_val_t' to 'const std::nothrow_t' for 2nd argument}}
+  // expected-note@new:214 {{candidate function not viable: no known conversion from 'std::align_val_t' to 'void *' for 2nd argument}}
+  // expected-note@new:187 {{candidate function not viable: requires single argument '__sz', but 2 arguments were provided}}
+  // expected-note@new:205 {{candidate function not viable: requires 3 arguments, but 2 were provided}}
+#else
+// expected-no-diagnostics
+#endif
+#else
+// expected-no-diagnostics
+#endif
+  return 0;
+}
Index: include/new
===
--- include/new
+++ include/new
@@ -193,20 +193,20 @@
 #endif
 
 #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, std::align_val_t) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  operator delete(void* __p, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
 #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void  operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  operator delete(void* __p, std::size_t __sz, std::al

[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:730
+
+Mapping TreeComparator::matchTopDown() const {
+  PriorityList L1(T1);

Johannes, it seems to me that your implementation of the top-down portion of 
the GumTree algorithm doesn't use the `an empty list A of candidate mappings` 
that's described in the paper (and that you have in the Python prototype). Is 
that correct or am I missing something?


https://reviews.llvm.org/D34329



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


[PATCH] D33681: [OpenCL] Allow function declaration with empty argument list.

2017-06-23 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

Ping.

Although this patch is already accepted, I'd like to confirm that I can commit 
the latest update with changes in test/SemaOpenCL/invalid-pipes-cl2.0.cl.

Thanks.


https://reviews.llvm.org/D33681



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


r306074 - [WebAssembly] Add default -allow-undefined-file to linker args

2017-06-23 Thread Sam Clegg via cfe-commits
Author: sbc
Date: Thu Jun 22 19:02:55 2017
New Revision: 306074

URL: http://llvm.org/viewvc/llvm-project?rev=306074&view=rev
Log:
[WebAssembly] Add default -allow-undefined-file to linker args

Also, don't use the outdated lib32/lib64 naming of files
within the sysroot. The more modern/flexible approach
IIUC is to use seperate sysroots or /lib/
and /include/.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
cfe/trunk/test/Driver/wasm-toolchain.c

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp?rev=306074&r1=306073&r2=306074&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp Thu Jun 22 19:02:55 2017
@@ -83,6 +83,8 @@ void wasm::Linker::ConstructJob(Compilat
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 
+CmdArgs.push_back("-allow-undefined-file");
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("wasm.syms")));
 CmdArgs.push_back("-lc");
 CmdArgs.push_back("-lcompiler_rt");
   }
@@ -104,8 +106,7 @@ WebAssembly::WebAssembly(const Driver &D
 
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-  getFilePaths().push_back(
-  getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64"));
+  getFilePaths().push_back(getDriver().SysRoot + "/lib");
 }
 
 bool WebAssembly::IsMathErrnoDefault() const { return false; }

Modified: cfe/trunk/test/Driver/wasm-toolchain.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/wasm-toolchain.c?rev=306074&r1=306073&r2=306074&view=diff
==
--- cfe/trunk/test/Driver/wasm-toolchain.c (original)
+++ cfe/trunk/test/Driver/wasm-toolchain.c Thu Jun 22 19:02:55 2017
@@ -27,18 +27,18 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib32" "crt1.o" "crti.o" 
"[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "crti.o" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
 
 // A basic C link command-line with optimization. WebAssembly is somewhat
 // special in enabling --gc-sections by default.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib32" 
"crt1.o" "crti.o" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" "crt1.o" 
"crti.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" 
"crtn.o" "-o" "a.out"
 
 // Ditto, but ensure that a user --no-gc-sections comes after the
 // default --gc-sections.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo -Wl,--no-gc-sections %s 2>&1 | FileCheck 
-check-prefix=NO_GC_SECTIONS %s
 // NO_GC_SECTIONS: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib32" 
"crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-lc" "-lcompiler_rt" "crtn.o" 
"-o" "a.out"
+// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" 
"crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-allow-undefined-file" 
"wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"


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


[PATCH] D32642: [Analyzer] Iterator Checker - Part 2: Increment, decrement operators and ahead-of-begin checks

2017-06-23 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

Now I can improve `SValBuilder` to compare `{conj_X}+n` to `conj_X}+m`, but I 
am not sure if it helps to simplify `compare()` much. How to handle cases where 
I have to compare `{conj_X}+n` to `{conj_Y}+m`, an we have a range `[k..k]` for 
`{conj_X}-{conj_Y}` in the constraint manager. I still need to decompose the 
two expressions, retrieve the single length range and adjust one of the sides 
of the comparison. I think I should not add such complicated code (i.e. 
retrieving single length range from the constrain manager) to `SValBuilder`.


https://reviews.llvm.org/D32642



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-06-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Daniel is a better reviewer here than myself. A few cents from me though: why 
do we want to make an exception for comments and not for regular code?


https://reviews.llvm.org/D33589



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


[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Link to failure: 
http://bb.pgr.jp/builders/test-clang-msc-x64-on-i686-linux-RA/builds/3777/steps/test_clang/logs/Clang%20%3A%3A%20Index__ctor-init-source-loc.cpp


Repository:
  rL LLVM

https://reviews.llvm.org/D32439



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


[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Serge, the test seems to be failing on linux 
(http://bb.pgr.jp/builders/test-clang-msc-x64-on-i686-linux-RA). Can you take a 
look? I will have to revert it if we can't fix it soon.


Repository:
  rL LLVM

https://reviews.llvm.org/D32439



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


[PATCH] D32642: [Analyzer] Iterator Checker - Part 2: Increment, decrement operators and ahead-of-begin checks

2017-06-23 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 103728.
baloghadamsoftware added a comment.

`SymbolManager::getSymIntExpr()` replaced by `SValBuilder::evalBinOp()`, 
function `compact()` eliminated.


https://reviews.llvm.org/D32642

Files:
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/diagnostics/explicit-suppression.cpp
  test/Analysis/iterator-range.cpp

Index: test/Analysis/iterator-range.cpp
===
--- test/Analysis/iterator-range.cpp
+++ test/Analysis/iterator-range.cpp
@@ -13,7 +13,102 @@
   }
 }
 
+void simple_good_end_negated(const std::vector &v) {
+  auto i = v.end();
+  if (!(i == v.end())) {
+clang_analyzer_warnIfReached();
+*i; // no-warning
+  }
+}
+
 void simple_bad_end(const std::vector &v) {
   auto i = v.end();
   *i; // expected-warning{{Iterator accessed outside of its range}}
 }
+
+void simple_good_begin(const std::vector &v) {
+  auto i = v.begin();
+  if (i != v.begin()) {
+clang_analyzer_warnIfReached();
+*--i; // no-warning
+  }
+}
+
+void simple_good_begin_negated(const std::vector &v) {
+  auto i = v.begin();
+  if (!(i == v.begin())) {
+clang_analyzer_warnIfReached();
+*--i; // no-warning
+  }
+}
+
+void simple_bad_begin(const std::vector &v) {
+  auto i = v.begin();
+  *--i; // expected-warning{{Iterator accessed outside of its range}}
+}
+
+void copy(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  *i2; // expected-warning{{Iterator accessed outside of its range}}
+}
+
+void decrease(const std::vector &v) {
+  auto i = v.end();
+  --i;
+  *i; // no-warning
+}
+
+void copy_and_decrease1(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  --i1;
+  *i1; // no-warning
+}
+
+void copy_and_decrease2(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  --i1;
+  *i2; // expected-warning{{Iterator accessed outside of its range}}
+}
+
+void copy_and_increase1(const std::vector &v) {
+  auto i1 = v.begin();
+  auto i2 = i1;
+  ++i1;
+  if (i1 == v.end())
+*i2; // no-warning
+}
+
+void copy_and_increase2(const std::vector &v) {
+  auto i1 = v.begin();
+  auto i2 = i1;
+  ++i1;
+  if (i2 == v.end())
+*i2; // expected-warning{{Iterator accessed outside of its range}}
+}
+
+void tricky(std::vector &V, int e) {
+  const auto first = V.begin();
+  const auto comp1 = (first != V.end()), comp2 = (first == V.end());
+  if (comp1)
+*first;
+}
+
+void loop(std::vector &V, int e) {
+  auto start = V.begin();
+  while (true) {
+auto item = std::find(start, V.end(), e);
+if (item == V.end())
+  break;
+*item;  // no-warning
+start = ++item; // no-warning
+  }
+}
+
+void bad_move(std::list &L1, std::list &L2) {
+  auto i0 = --L2.cend();
+  L1 = std::move(L2);
+  *++i0; // expected-warning{{Iterator accessed outside of its range}}
+}
Index: test/Analysis/diagnostics/explicit-suppression.cpp
===
--- test/Analysis/diagnostics/explicit-suppression.cpp
+++ test/Analysis/diagnostics/explicit-suppression.cpp
@@ -19,6 +19,6 @@
 void testCopyNull(C *I, C *E) {
   std::copy(I, E, (C *)0);
 #ifndef SUPPRESSED
-  // expected-warning@../Inputs/system-header-simulator-cxx.h:490 {{Called C++ object pointer is null}}
+  // expected-warning@../Inputs/system-header-simulator-cxx.h:514 {{Called C++ object pointer is null}}
 #endif
 }
Index: test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- test/Analysis/Inputs/system-header-simulator-cxx.h
+++ test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -252,6 +252,12 @@
   return size_t(_finish - _start);
 }
 
+void clear();
+
+void push_back(const T &value);
+void push_back(T &&value);
+void pop_back();
+
 T &operator[](size_t n) {
   return _start[n];
 }
@@ -295,6 +301,8 @@
 list& operator=(list &&other);
 list& operator=(std::initializer_list ilist);
 
+void clear();
+
 iterator begin() { return iterator(_start); }
 const_iterator begin() const { return const_iterator(_start); }
 const_iterator cbegin() const { return const_iterator(_start); }
@@ -330,6 +338,16 @@
   return size_t(_finish - _start);
 }
 
+void clear();
+
+void push_back(const T &value);
+void push_back(T &&value);
+void pop_back();
+
+void push_front(const T &value);
+void push_front(T &&value);
+void pop_front();
+
 T &operator[](size_t n) {
   return _start[n];
 }
@@ -369,6 +387,12 @@
 forward_list(forward_list &&other);
 ~forward_list();
 
+void clear();
+
+void push_front(const T &value);
+void push_front(T &&value);
+void pop_front();
+
 iterator begin() { return iterator(_start); }
 const_iterator begin() const { return const_iterator(_start); }
 const_iterator cbegin() con

[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-23 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306103: PR26195: Set correct NestedNameSpecifierLoc for the 
dependent initializer (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D32439?vs=103703&id=103727#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32439

Files:
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/test/Index/ctor-init-source-loc.cpp

Index: cfe/trunk/test/Index/ctor-init-source-loc.cpp
===
--- cfe/trunk/test/Index/ctor-init-source-loc.cpp
+++ cfe/trunk/test/Index/ctor-init-source-loc.cpp
@@ -0,0 +1,117 @@
+// RUN: c-index-test -test-load-source all %s | FileCheck %s
+template
+struct Derived:  MyBase::InnerIterator
+{
+Derived() : MyBase::InnerIterator() {}
+// CHECK:  TypeRef=MyBase:2:19 Extent=[5:17 - 5:23]
+};
+
+template
+struct Derived2:  MyBase::Deeper::InnerIterator
+{
+Derived2() : MyBase::Deeper::InnerIterator() {}
+// CHECK:  TypeRef=MyBase:9:19 Extent=[12:18 - 12:24]
+};
+
+template
+struct Templ;
+
+template
+struct Derived3:  Templ::InnerIterator
+{
+Derived3() : Templ::InnerIterator() {}
+// CHECK: TemplateRef=Templ:17:8 Extent=[22:18 - 22:23]
+// CHECK: TypeRef=MyBase:19:19 Extent=[22:24 - 22:30]
+};
+
+
+struct Outer {
+template 
+struct Inner {
+typedef Q Parm;
+};
+};
+
+template
+struct Derived4:  Outer::Inner::Parm
+{
+Derived4() : Outer::Inner::Parm() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[38:18 - 38:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[38:25 - 38:30]
+// CHECK: TypeRef=Q:35:19 Extent=[38:31 - 38:32]
+};
+
+template
+struct Derived5:  Outer::Inner::Parm::InnerIterator
+{
+Derived5() : Outer::Inner::Parm::InnerIterator() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[47:18 - 47:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[47:25 - 47:30]
+// CHECK: TypeRef=Q:44:19 Extent=[47:31 - 47:32]
+};
+
+template
+struct Derived6:  Outer::Inner
+{
+Derived6() : Outer::Inner() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[56:18 - 56:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[56:25 - 56:30]
+// CHECK: TypeRef=Q:53:19 Extent=[56:31 - 56:32]
+};
+
+struct Base {};
+
+struct Derived7:  Outer::Inner::Parm
+{
+Derived7() : Outer::Inner::Parm() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[66:18 - 66:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[66:25 - 66:30]
+// CHECK: TypeRef=struct Base:62:8 Extent=[66:31 - 66:35]
+};
+
+struct Derived8:  Outer::Inner
+{
+Derived8() : Outer::Inner() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[74:18 - 74:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[74:25 - 74:30]
+// CHECK: TypeRef=struct Base:62:8 Extent=[74:31 - 74:35]
+};
+
+namespace Namespace {
+template struct Templ;
+
+struct Outer {
+template 
+struct Inner {
+typedef Q Parm;
+};
+};
+}
+
+template
+struct Derived9:  Namespace::Templ::InnerIterator
+{
+Derived9() : Namespace::Templ::InnerIterator() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[94:18 - 94:27]
+// CHECK: TemplateRef=Templ:81:33 Extent=[94:29 - 94:34]
+// CHECK: TypeRef=MyBase:91:19 Extent=[94:35 - 94:41]
+};
+
+template
+struct Derived10:  Namespace::Templ
+{
+Derived10() : Namespace::Templ() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[103:19 - 103:28]
+// CHECK: TemplateRef=Templ:81:33 Extent=[103:30 - 103:35]
+// CHECK: TypeRef=MyBase:100:19 Extent=[103:36 - 103:42]
+};
+
+template
+struct Derived11:  Namespace::Outer::Inner::Parm
+{
+Derived11() : Namespace::Outer::Inner::Parm() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[112:19 - 112:28]
+// CHECK: TypeRef=struct Namespace::Outer:83:12 Extent=[112:30 - 112:35]
+// CHECK: TemplateRef=Inner:85:16 Extent=[112:37 - 112:42]
+// CHECK: TypeRef=MyBase:109:19 Extent=[112:43 - 112:49]
+};
Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -3778,6 +3778,15 @@
   if (BaseType.isNull())
 return true;
 
+  TInfo = Context.CreateTypeSourceInfo(BaseType);
+  DependentNameTypeLoc TL =
+  TInfo->getTypeLoc().castAs();
+  if (!TL.isNull()) {
+TL.setNameLoc(IdLoc);
+TL.setElaboratedKeywordLoc(SourceLocation());
+TL.setQualifierLoc(SS.getWithLocInContext(Context));
+  }
+
   R.clear();
   R.setLookupName(MemberOrBase);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r306103 - PR26195: Set correct NestedNameSpecifierLoc for the dependent initializer

2017-06-23 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Jun 23 09:10:07 2017
New Revision: 306103

URL: http://llvm.org/viewvc/llvm-project?rev=306103&view=rev
Log:
PR26195: Set correct NestedNameSpecifierLoc for the dependent initializer

This commit fixes incorrect source positions of dependent c'tor initializers
like in the following code:

template
struct Derived: MyBase::InnerIterator
{

Derived() : MyBase::InnerIterator() {} /// This line is problematic: all 
positions point to InnerIterator and nothing points to MyBase
};

Patch by Serge Preis!

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

Added:
cfe/trunk/test/Index/ctor-init-source-loc.cpp
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=306103&r1=306102&r2=306103&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Jun 23 09:10:07 2017
@@ -3778,6 +3778,15 @@ Sema::BuildMemInitializer(Decl *Construc
   if (BaseType.isNull())
 return true;
 
+  TInfo = Context.CreateTypeSourceInfo(BaseType);
+  DependentNameTypeLoc TL =
+  TInfo->getTypeLoc().castAs();
+  if (!TL.isNull()) {
+TL.setNameLoc(IdLoc);
+TL.setElaboratedKeywordLoc(SourceLocation());
+TL.setQualifierLoc(SS.getWithLocInContext(Context));
+  }
+
   R.clear();
   R.setLookupName(MemberOrBase);
 }

Added: cfe/trunk/test/Index/ctor-init-source-loc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/ctor-init-source-loc.cpp?rev=306103&view=auto
==
--- cfe/trunk/test/Index/ctor-init-source-loc.cpp (added)
+++ cfe/trunk/test/Index/ctor-init-source-loc.cpp Fri Jun 23 09:10:07 2017
@@ -0,0 +1,117 @@
+// RUN: c-index-test -test-load-source all %s | FileCheck %s
+template
+struct Derived:  MyBase::InnerIterator
+{
+Derived() : MyBase::InnerIterator() {}
+// CHECK:  TypeRef=MyBase:2:19 Extent=[5:17 - 5:23]
+};
+
+template
+struct Derived2:  MyBase::Deeper::InnerIterator
+{
+Derived2() : MyBase::Deeper::InnerIterator() {}
+// CHECK:  TypeRef=MyBase:9:19 Extent=[12:18 - 12:24]
+};
+
+template
+struct Templ;
+
+template
+struct Derived3:  Templ::InnerIterator
+{
+Derived3() : Templ::InnerIterator() {}
+// CHECK: TemplateRef=Templ:17:8 Extent=[22:18 - 22:23]
+// CHECK: TypeRef=MyBase:19:19 Extent=[22:24 - 22:30]
+};
+
+
+struct Outer {
+template 
+struct Inner {
+typedef Q Parm;
+};
+};
+
+template
+struct Derived4:  Outer::Inner::Parm
+{
+Derived4() : Outer::Inner::Parm() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[38:18 - 38:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[38:25 - 38:30]
+// CHECK: TypeRef=Q:35:19 Extent=[38:31 - 38:32]
+};
+
+template
+struct Derived5:  Outer::Inner::Parm::InnerIterator
+{
+Derived5() : Outer::Inner::Parm::InnerIterator() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[47:18 - 47:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[47:25 - 47:30]
+// CHECK: TypeRef=Q:44:19 Extent=[47:31 - 47:32]
+};
+
+template
+struct Derived6:  Outer::Inner
+{
+Derived6() : Outer::Inner() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[56:18 - 56:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[56:25 - 56:30]
+// CHECK: TypeRef=Q:53:19 Extent=[56:31 - 56:32]
+};
+
+struct Base {};
+
+struct Derived7:  Outer::Inner::Parm
+{
+Derived7() : Outer::Inner::Parm() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[66:18 - 66:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[66:25 - 66:30]
+// CHECK: TypeRef=struct Base:62:8 Extent=[66:31 - 66:35]
+};
+
+struct Derived8:  Outer::Inner
+{
+Derived8() : Outer::Inner() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[74:18 - 74:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[74:25 - 74:30]
+// CHECK: TypeRef=struct Base:62:8 Extent=[74:31 - 74:35]
+};
+
+namespace Namespace {
+template struct Templ;
+
+struct Outer {
+template 
+struct Inner {
+typedef Q Parm;
+};
+};
+}
+
+template
+struct Derived9:  Namespace::Templ::InnerIterator
+{
+Derived9() : Namespace::Templ::InnerIterator() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[94:18 - 94:27]
+// CHECK: TemplateRef=Templ:81:33 Extent=[94:29 - 94:34]
+// CHECK: TypeRef=MyBase:91:19 Extent=[94:35 - 94:41]
+};
+
+template
+struct Derived10:  Namespace::Templ
+{
+Derived10() : Namespace::Templ() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[103:19 - 103:28]
+// CHECK: TemplateRef=Templ:81:33 Extent=[103:30 - 103:35]
+// CHECK: TypeRef=MyBase:100:19 Extent=[103:36 - 103:42]
+};
+
+template
+struct Derived11:  Namespace::Outer::Inner::Parm
+{
+Derived11() : Namespace::Outer::Inner::Parm() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[112:19 

[PATCH] D16403: Add scope information to CFG

2017-06-23 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Hi Matthias,
I have posted a comment about review duplication (more than a year ago!) in 
your review but you haven't answered. So, all this time we were thinking that 
you do separate non-related work.
@dcoughlin As a reviewer of both patches - could you tell us what's the 
difference between them? And how are we going to resolve this issue?


Repository:
  rL LLVM

https://reviews.llvm.org/D16403



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


[PATCH] D34513: [NFC] Update to account for DiagnosticRenderer use of FullSourceLoc

2017-06-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG. Looks like a pretty mechanical change.


https://reviews.llvm.org/D34513



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


[PATCH] D16403: Add scope information to CFG

2017-06-23 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre added a comment.

Please consider also https://reviews.llvm.org/D15031
It already handles all possible control flows. Instead of ScopeBegin and 
ScopeEnd,
it introduces LifetimeEnds elements. It's a more specific in that is also
correctly models the order of lifetime expiry of variables and the order
or destructor calls / lifetime ending.


Repository:
  rL LLVM

https://reviews.llvm.org/D16403



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


[PATCH] D34546: docs: Add documentation for the ThinLTO cache pruning policy string.

2017-06-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D34546



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


[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-23 Thread Serge Preis via Phabricator via cfe-commits
Serge_Preis added a comment.

Thank you!


https://reviews.llvm.org/D32439



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


[PATCH] D34395: clang-format: add options to merge empty record body

2017-06-23 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D34395



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


[PATCH] D32478: [clang-format] Fix AlignOperands when BreakBeforeBinaryOperators is set

2017-06-23 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D32478



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


[PATCH] D34238: clang-format: Do not binpack initialization lists

2017-06-23 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D34238



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


[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

This LGTM. I will commit it for you.


https://reviews.llvm.org/D32439



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


[PATCH] D16403: Add scope information to CFG

2017-06-23 Thread Maxim Ostapenko via Phabricator via cfe-commits
m.ostapenko updated this revision to Diff 103719.
m.ostapenko set the repository for this revision to rL LLVM.
m.ostapenko added a project: clang.
m.ostapenko added a comment.

So, updating the diff. This is still a very experimental version and any 
feedback would be greatly appreciated.
Current patch should support basic {If, While, For, Compound, Switch}Stmts as 
well as their interactions with {Break, Continue, Return}Stmts.
GotoStmt and CXXForRangeStmt are not supported at this moment.


Repository:
  rL LLVM

https://reviews.llvm.org/D16403

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

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

[PATCH] D30748: [Lexer] Finding beginning of token with escaped new line

2017-06-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Sorry for the delay, I was on vacation.

This looks much better now, thanks! A few more comments though.




Comment at: lib/Lex/Lexer.cpp:460
+/// \brief Check if new line pointed by Str is escaped.
+bool isNewLineEscaped(const char *BufferStart, const char *Str) {
+  assert(isVerticalWhitespace(Str[0]));

The way the function is exposed to the test may lead to confusion. I'd either 
properly declare it in the header (and place it in a namespace, if it is not 
yet) or at least leave a comment here that the function is not static, since it 
needs to be exposed to the test.



Comment at: lib/Lex/Lexer.cpp:474
+  // Rewind to first non-space character:
+  while (isHorizontalWhitespace(*Str) && Str > BufferStart)
+--Str;

nit: Placing the `Str > BufferStart` first would make it more obvious that 
`Str` can be safely dereferenced.



Comment at: unittests/Lex/LexerTest.cpp:371-386
+  std::vector> TestLines = {
+  {true, "\\\r"},{true, "\\\n"},{true, "\\\r\n"},
+  {true, "\\\n\r"},  {true, "\\ \t\v\f\r"}, {true, "\\ \t\v\f\r\n"},
+  {false, "\\\r\r"}, {false, "\\\r\r\n"},   {false, "\\\n\n"},
+  {false, "\r"}, {false, "\n"}, {false, "\r\n"},
+  {false, "\n\r"},   {false, "\r\r"},   {false, "\n\n"}};
+

I would better unroll the loop:

  auto endsWithEscapedNewline = [] (const char *S) {
return isNewLineEscaped(S, S + strlen(S) - 1);
  };
  EXPECT_TRUE(endsWithEscapedNewline("\\\r"));
  EXPECT_TRUE(endsWithEscapedNewline("\\\n"));
  ...
  EXPECT_FALSE(endsWithEscapedNewline("\\\r\r"));
  ...

This would simplify the test and make EXPECT_* macro output sufficient to 
detect failing patterns without any clarifying messages.


https://reviews.llvm.org/D30748



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


r306094 - [clang-format] Add a SortUsingDeclaration option and enable it by default

2017-06-23 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Fri Jun 23 06:46:03 2017
New Revision: 306094

URL: http://llvm.org/viewvc/llvm-project?rev=306094&view=rev
Log:
[clang-format] Add a SortUsingDeclaration option and enable it by default

Summary:
This patch adds a `SortUsingDeclaration` style option and enables it for llvm
style.

Reviewers: klimek

Reviewed By: klimek

Subscribers: klimek

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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=306094&r1=306093&r2=306094&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Fri Jun 23 06:46:03 2017
@@ -1475,6 +1475,15 @@ the configuration (without a prefix: ``A
  #include "b.h" vs. #include "a.h"
  #include "a.h" #include "b.h"
 
+**SortUsingDeclarations** (``bool``)
+  If ``true``, clang-format will sort using declarations.
+
+  .. code-block:: c++
+
+ false: true:
+ using std::cout;   vs. using std::cin;
+ using std::cin;using std::cout;
+
 **SpaceAfterCStyleCast** (``bool``)
   If ``true``, a space is inserted after C style casts.
 

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=306094&r1=306093&r2=306094&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Fri Jun 23 06:46:03 2017
@@ -1270,6 +1270,14 @@ struct FormatStyle {
   /// \endcode
   bool SortIncludes;
 
+  /// \brief If ``true``, clang-format will sort using declarations.
+  /// \code
+  ///false: true:
+  ///using std::cout;   vs. using std::cin;
+  ///using std::cin;using std::cout;
+  /// \endcode
+  bool SortUsingDeclarations;
+
   /// \brief If ``true``, a space is inserted after C style casts.
   /// \code
   ///true:  false:

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=306094&r1=306093&r2=306094&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Jun 23 06:46:03 2017
@@ -379,6 +379,7 @@ template <> struct MappingTraits
+  AnalyzerPass;
+  SmallVector Passes;
+
+  if (Style.Language == FormatStyle::LK_Cpp) {
+if (Style.FixNamespaceComments)
+  Passes.emplace_back([&](const Environment &Env) {
+return NamespaceEndCommentsFixer(Env, Expanded).process();
+  });
 
-  if (Style.Language == FormatStyle::LK_Cpp &&
-  Style.FixNamespaceComments) {
-NamespaceEndCommentsFixer CommentsFixer(*Env, Expanded);
-return reformatAfterApplying(CommentsFixer);
+if (Style.SortUsingDeclarations)
+  Passes.emplace_back([&](const Environment &Env) {
+return UsingDeclarationsSorter(Env, Expanded).process();
+  });
   }
 
   if (Style.Language == FormatStyle::LK_JavaScript &&
-  Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) {
-JavaScriptRequoter Requoter(*Env, Expanded);
-return reformatAfterApplying(Requoter);
+  Style.JavaScriptQuotes != FormatStyle::JSQS_Leave)
+Passes.emplace_back([&](const Environment &Env) {
+  return JavaScriptRequoter(Env, Expanded).process();
+});
+
+  Passes.emplace_back([&](const Environment &Env) {
+return Formatter(Env, Expanded, Status).process();
+  });
+
+  std::unique_ptr Env =
+  Environment::CreateVirtualEnvironment(Code, FileName, Ranges);
+  llvm::Optional CurrentCode = None;
+  tooling::Replacements Fixes;
+  for (size_t I = 0, E = Passes.size(); I < E; ++I) {
+tooling::Replacements PassFixes = Passes[I](*Env);
+auto NewCode = applyAllReplacements(
+CurrentCode ? StringRef(*CurrentCode) : Code, PassFixes);
+if (NewCode) {
+  Fixes = Fixes.merge(PassFixes);
+  if (I + 1 < E) {
+CurrentCode = std::move(*NewCode);
+Env = Environment::CreateVirtualEnvironment(
+*CurrentCode, FileName,
+tooling::calculateRangesAfterReplacements(Fixes, Ranges));
+  }
+}
   }
 
-  Formatter Format(*Env, Expanded, Status);
-  return Format.process();
+  return Fixes;
 }
 
 tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm

[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

2017-06-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Ok, so now the null check `return.sloc.load` won't call the checker in 
compiler-rt and so the program won't `abort` and won't hit the `unreachable`. I 
have one question tough:

This patch changes the behavior of this sanitizer for the example that I gave 
above. Previously a runtime diagnostic was emitted, but now there is none. 
While I'm not saying that the previous behaviour was correct, I'm wondering if 
the new behaviour is right.  I think that for C++ it makes sense, but I don't 
know the right answer for C. I'm leaning more towards the new behaviour, since 
technically in C falling off without returning a value is not UB unless that 
return value is used by the caller. But at the same time, since we don't 
diagnose `return` UB for C, maybe it's still worth diagnosing this particular 
issue? The user might not catch it otherwise at all (or they might catch it 
later when they try to access it, but by that point they might not know where 
the pointer came from). WDYT?


https://reviews.llvm.org/D34299



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


[PATCH] D34512: [libTooling] Add preliminary Cross Translation Unit support for libTooling

2017-06-23 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: include/clang/Tooling/CrossTranslationUnit.h:53-58
+  /// \p CrossTUDir directory, called \p IndexName. In case the declaration is
+  /// found in the index the corresponding AST file will be loaded and the
+  /// definition of the function will be merged into the original AST using
+  /// the AST Importer. The declaration with the definition will be returned.
+  ///
+  /// Note that the AST files should also be in the \p CrossTUDir.

xazax.hun wrote:
> klimek wrote:
> > In the future we'll want to create an index interface around this (which 
> > will probably serve also what the refactoring integration would be based 
> > on), instead of piping files and directories into all classes.
> > 
> > Perhaps we can start this by already pulling out a class ProjectIndex or 
> > somesuch,  with methods like loadASTDefining(...)?
> > 
> While I do agree to have an interface for that would be really good, but 
> maybe it would be better to first review and accept this patch and after that 
> design the interface in a follow-up patch (so https://reviews.llvm.org/D30691 
> is not blocked). What do you think?  
I'm generally fine with that, and mainly looped in other folks to see whether 
anybody else has concerns.


https://reviews.llvm.org/D34512



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


[PATCH] D34552: [clang-format] Update dump_format_style.py to indent nested fields

2017-06-23 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306093: [clang-format] Update dump_format_style.py to indent 
nested fields (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D34552?vs=103709&id=103711#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34552

Files:
  cfe/trunk/docs/ClangFormatStyleOptions.rst
  cfe/trunk/docs/tools/dump_format_style.py

Index: cfe/trunk/docs/ClangFormatStyleOptions.rst
===
--- cfe/trunk/docs/ClangFormatStyleOptions.rst
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst
@@ -538,158 +538,158 @@
 
   * ``bool AfterClass`` Wrap class definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-class foo {};
+  true:
+  class foo {};
 
-false:
-class foo
-{};
+  false:
+  class foo
+  {};
 
   * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-if (foo())
-{
-} else
-{}
-for (int i = 0; i < 10; ++i)
-{}
+  true:
+  if (foo())
+  {
+  } else
+  {}
+  for (int i = 0; i < 10; ++i)
+  {}
 
-false:
-if (foo()) {
-} else {
-}
-for (int i = 0; i < 10; ++i) {
-}
+  false:
+  if (foo()) {
+  } else {
+  }
+  for (int i = 0; i < 10; ++i) {
+  }
 
   * ``bool AfterEnum`` Wrap enum definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-enum X : int
-{
-  B
-};
+  true:
+  enum X : int
+  {
+B
+  };
 
-false:
-enum X : int { B };
+  false:
+  enum X : int { B };
 
   * ``bool AfterFunction`` Wrap function definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-void foo()
-{
-  bar();
-  bar2();
-}
+  true:
+  void foo()
+  {
+bar();
+bar2();
+  }
 
-false:
-void foo() {
-  bar();
-  bar2();
-}
+  false:
+  void foo() {
+bar();
+bar2();
+  }
 
   * ``bool AfterNamespace`` Wrap namespace definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-namespace
-{
-int foo();
-int bar();
-}
+  true:
+  namespace
+  {
+  int foo();
+  int bar();
+  }
 
-false:
-namespace {
-int foo();
-int bar();
-}
+  false:
+  namespace {
+  int foo();
+  int bar();
+  }
 
   * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
 
   * ``bool AfterStruct`` Wrap struct definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-struct foo
-{
-  int x;
-};
+  true:
+  struct foo
+  {
+int x;
+  };
 
-false:
-struct foo {
-  int x;
-};
+  false:
+  struct foo {
+int x;
+  };
 
   * ``bool AfterUnion`` Wrap union definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-union foo
-{
-  int x;
-}
+  true:
+  union foo
+  {
+int x;
+  }
 
-false:
-union foo {
-  int x;
-}
+  false:
+  union foo {
+int x;
+  }
 
   * ``bool BeforeCatch`` Wrap before ``catch``.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-try {
-  foo();
-}
-catch () {
-}
+  true:
+  try {
+foo();
+  }
+  catch () {
+  }
 
-false:
-try {
-  foo();
-} catch () {
-}
+  false:
+  try {
+foo();
+  } catch () {
+  }
 
   * ``bool BeforeElse`` Wrap before ``else``.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-if (foo()) {
-}
-else {
-}
+  true:
+  if (foo()) {
+  }
+  else {
+  }
 
-false:
-if (foo()) {
-} else {
-}
+  false:
+  if (foo()) {
+  } else {
+  }
 
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
   * ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be put on a single line.
-  This option is used only if the opening brace of the function has
-  already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
-  set, and the function could/should not be put on a single line (as per
-  `AllowShortFunctionsOnASingleLine` and constructor formatting options).
+This option is used only if the opening brace of the function has
+already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
+set, and the function could/should not be put on a single line (as per
+`AllowShortFunctionsOnASingleLine` and constructor formatting options).
 
-  .. code-block:: c++
+.. code-block:: c++
 
-int f()   vs.   inf f()
-{}  {
-}
+  int f()   vs.   inf f()

r306093 - [clang-format] Update dump_format_style.py to indent nested fields

2017-06-23 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Fri Jun 23 06:29:40 2017
New Revision: 306093

URL: http://llvm.org/viewvc/llvm-project?rev=306093&view=rev
Log:
[clang-format] Update dump_format_style.py to indent nested fields

Summary:
This updates the format options documentation script to indent the
documentation of nested fields. The previous format caused some problems,
as when a bulleted list ends with a multiline comment. See the buildbot failure
http://lab.llvm.org:8011/builders/clang-sphinx-docs/builds/10020/steps/docs-clang-html/logs/stdio

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/docs/tools/dump_format_style.py

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=306093&r1=306092&r2=306093&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Fri Jun 23 06:29:40 2017
@@ -538,158 +538,158 @@ the configuration (without a prefix: ``A
 
   * ``bool AfterClass`` Wrap class definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-class foo {};
+  true:
+  class foo {};
 
-false:
-class foo
-{};
+  false:
+  class foo
+  {};
 
   * ``bool AfterControlStatement`` Wrap control statements 
(``if``/``for``/``while``/``switch``/..).
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-if (foo())
-{
-} else
-{}
-for (int i = 0; i < 10; ++i)
-{}
-
-false:
-if (foo()) {
-} else {
-}
-for (int i = 0; i < 10; ++i) {
-}
+  true:
+  if (foo())
+  {
+  } else
+  {}
+  for (int i = 0; i < 10; ++i)
+  {}
+
+  false:
+  if (foo()) {
+  } else {
+  }
+  for (int i = 0; i < 10; ++i) {
+  }
 
   * ``bool AfterEnum`` Wrap enum definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-enum X : int
-{
-  B
-};
+  true:
+  enum X : int
+  {
+B
+  };
 
-false:
-enum X : int { B };
+  false:
+  enum X : int { B };
 
   * ``bool AfterFunction`` Wrap function definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-void foo()
-{
-  bar();
-  bar2();
-}
-
-false:
-void foo() {
-  bar();
-  bar2();
-}
+  true:
+  void foo()
+  {
+bar();
+bar2();
+  }
+
+  false:
+  void foo() {
+bar();
+bar2();
+  }
 
   * ``bool AfterNamespace`` Wrap namespace definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-namespace
-{
-int foo();
-int bar();
-}
-
-false:
-namespace {
-int foo();
-int bar();
-}
+  true:
+  namespace
+  {
+  int foo();
+  int bar();
+  }
+
+  false:
+  namespace {
+  int foo();
+  int bar();
+  }
 
   * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (``@autoreleasepool``, 
interfaces, ..).
 
   * ``bool AfterStruct`` Wrap struct definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-struct foo
-{
-  int x;
-};
-
-false:
-struct foo {
-  int x;
-};
+  true:
+  struct foo
+  {
+int x;
+  };
+
+  false:
+  struct foo {
+int x;
+  };
 
   * ``bool AfterUnion`` Wrap union definitions.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-union foo
-{
-  int x;
-}
-
-false:
-union foo {
-  int x;
-}
+  true:
+  union foo
+  {
+int x;
+  }
+
+  false:
+  union foo {
+int x;
+  }
 
   * ``bool BeforeCatch`` Wrap before ``catch``.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-try {
-  foo();
-}
-catch () {
-}
-
-false:
-try {
-  foo();
-} catch () {
-}
+  true:
+  try {
+foo();
+  }
+  catch () {
+  }
+
+  false:
+  try {
+foo();
+  } catch () {
+  }
 
   * ``bool BeforeElse`` Wrap before ``else``.
 
-  .. code-block:: c++
+.. code-block:: c++
 
-true:
-if (foo()) {
-}
-else {
-}
-
-false:
-if (foo()) {
-} else {
-}
+  true:
+  if (foo()) {
+  }
+  else {
+  }
+
+  false:
+  if (foo()) {
+  } else {
+  }
 
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
   * ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be 
put on a single line.
-  This option is used only if the opening brace of the function has
-  already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
-  set, and the function could/should not 

[PATCH] D33304: [clang-tidy][Part1] Add a new module Android and three new checks.

2017-06-23 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG with one nit.




Comment at: clang-tidy/android/FileOpenFlagCheck.cpp:24
+
+bool HasCloseOnExecFlag(const Expr *Flags, const SourceManager &SM,
+const LangOptions &LangOpts) {

nit: "Function names should be verb phrases (as they represent actions), and 
command-like function should be imperative. The name should be camel case, and 
start with a lower case letter (e.g. openFile() or isFoo())." 
(http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly)


https://reviews.llvm.org/D33304



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


[PATCH] D34512: [libTooling] Add preliminary Cross Translation Unit support for libTooling

2017-06-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 103710.
xazax.hun added a comment.

- Removed an unrelated change
- Made the unit test more strict


https://reviews.llvm.org/D34512

Files:
  include/clang/Tooling/CrossTranslationUnit.h
  lib/AST/ASTImporter.cpp
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CrossTranslationUnit.cpp
  test/Analysis/func-mapping-test.cpp
  test/CMakeLists.txt
  test/lit.cfg
  tools/CMakeLists.txt
  tools/clang-func-mapping/CMakeLists.txt
  tools/clang-func-mapping/ClangFnMapGen.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/CrossTranslationUnitTest.cpp

Index: unittests/Tooling/CrossTranslationUnitTest.cpp
===
--- /dev/null
+++ unittests/Tooling/CrossTranslationUnitTest.cpp
@@ -0,0 +1,98 @@
+//===- unittest/Tooling/CrossTranslationUnitTest.cpp - Tooling unit tests -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/CrossTranslationUnit.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace tooling {
+
+namespace {
+StringRef IndexFileName = "index.txt";
+StringRef ASTFileName = "f.ast";
+StringRef DefinitionFileName = "input.cc";
+
+class CTUASTConsumer : public clang::ASTConsumer {
+public:
+  explicit CTUASTConsumer(clang::CompilerInstance &CI, bool *Success)
+  : CTU(CI), Success(Success) {}
+
+  void HandleTranslationUnit(ASTContext &Ctx) {
+const TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
+const FunctionDecl *FD = nullptr;
+for (const Decl *D : TU->decls()) {
+  FD = dyn_cast(D);
+  if (FD && FD->getName() == "f")
+break;
+}
+assert(FD);
+bool OrigFDHasBody = FD->hasBody();
+
+// Prepare the index file and the AST file.
+std::error_code EC;
+llvm::raw_fd_ostream OS(IndexFileName, EC, llvm::sys::fs::F_Text);
+OS << "c:@F@f#I# " << ASTFileName << "\n";
+OS.flush();
+StringRef SourceText = "int f(int) { return 0; }\n";
+// This file must exist since the saved ASTFile will reference it.
+llvm::raw_fd_ostream OS2(DefinitionFileName, EC, llvm::sys::fs::F_Text);
+OS2 << SourceText;
+OS2.flush();
+std::unique_ptr ASTWithDefinition =
+buildASTFromCode(SourceText);
+ASTWithDefinition->Save(ASTFileName);
+
+// Load the definition from the AST file.
+const FunctionDecl *NewFD =
+CTU.getCrossTUDefinition(FD, ".", IndexFileName);
+
+*Success = NewFD && NewFD->hasBody() && !OrigFDHasBody;
+  }
+
+private:
+  CrossTranslationUnit CTU;
+  bool *Success;
+};
+
+class CTUAction : public clang::ASTFrontendAction {
+public:
+  CTUAction(bool *Success) : Success(Success) {}
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance &CI, StringRef) override {
+return llvm::make_unique(CI, Success);
+  }
+
+private:
+  bool *Success;
+};
+
+} // end namespace
+
+TEST(CrossTranslationUnit, CanLoadFunctionDefinition) {
+  bool Success = false;
+  EXPECT_TRUE(runToolOnCode(new CTUAction(&Success), "int f(int);"));
+  EXPECT_TRUE(Success);
+  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
+  EXPECT_FALSE((bool)llvm::sys::fs::remove(IndexFileName));
+  EXPECT_TRUE(llvm::sys::fs::exists(ASTFileName));
+  EXPECT_FALSE((bool)llvm::sys::fs::remove(ASTFileName));
+  EXPECT_TRUE(llvm::sys::fs::exists(DefinitionFileName));
+  EXPECT_FALSE((bool)llvm::sys::fs::remove(DefinitionFileName));
+}
+
+} // end namespace tooling
+} // end namespace clang
Index: unittests/Tooling/CMakeLists.txt
===
--- unittests/Tooling/CMakeLists.txt
+++ unittests/Tooling/CMakeLists.txt
@@ -13,6 +13,7 @@
 add_clang_unittest(ToolingTests
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
+  CrossTranslationUnitTest.cpp
   FixItTest.cpp
   LookupTest.cpp
   QualTypeNamesTest.cpp
Index: tools/clang-func-mapping/ClangFnMapGen.cpp
===
--- /dev/null
+++ tools/clang-func-mapping/ClangFnMapGen.cpp
@@ -0,0 +1,127 @@
+//===- ClangFnMapGen.cpp ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//======//
+//
+// Clang tool which creates a list of defined functions and the files in which
+// they are defined.
+//
+//======//
+
+#i

  1   2   >