Re: [PATCH] D22900: Revert r244207 - Mark calls in thunk functions as tail-call optimization

2016-07-31 Thread Amjad Aboud via cfe-commits
aaboud added a comment.

Reverting https://reviews.llvm.org/rL244207, would be fine if we assure that 
PR24235, is fixed in another way.
I added Reid who helped reviewing the original patch 
https://reviews.llvm.org/D11476.


https://reviews.llvm.org/D22900



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


Re: [PATCH] D22900: Revert r244207 - Mark calls in thunk functions as tail-call optimization

2016-07-31 Thread David Majnemer via cfe-commits
majnemer added a comment.

In https://reviews.llvm.org/D22900#501597, @aaboud wrote:

> Reverting https://reviews.llvm.org/rL244207, would be fine if we assure that 
> PR24235, is fixed in another way.
>  I added Reid who helped reviewing the original patch 
> https://reviews.llvm.org/D11476.


ISTM that the DWARF spec intended such thunks to be encoded as 
`DW_AT_trampoline`.  That seems more appropriate than relying on codegen 
emitting a tailcall.  This way the debugger can make the policy decision of 
whether or not thunks should show up in the backtrace.

In any case, correctness must always trump all else.  Reverting to green should 
take precedence over a QoI bug like PR24235.


https://reviews.llvm.org/D22900



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


Re: [PATCH] D22900: Revert r244207 - Mark calls in thunk functions as tail-call optimization

2016-07-31 Thread Amjad Aboud via cfe-commits
aaboud added a comment.

> ISTM that the DWARF spec intended such thunks to be encoded as 
> `DW_AT_trampoline`.  That seems more appropriate than relying on codegen 
> emitting a tailcall.  This way the debugger can make the policy decision of 
> whether or not thunks should show up in the backtrace.

> 

> In any case, correctness must always trump all else.  Reverting to green 
> should take precedence over a QoI bug like PR24235.


I agree to the revert, though I am not sure about the new test, it looks too 
complected, especially the command line.
I will let David decide on accepting that test or ask for improvement.

Regards,
Amjad


https://reviews.llvm.org/D22900



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


Re: [PATCH] D22904: Fix two bugs for musl-libc on ARM

2016-07-31 Thread Renato Golin via cfe-commits
rengolin accepted this revision.
rengolin added a reviewer: rengolin.
rengolin added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


https://reviews.llvm.org/D22904



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


Re: [PATCH] D22725: [clang-tidy] Add check 'modernize-use-algorithm'

2016-07-31 Thread Jonas Devlieghere via cfe-commits
JDevlieghere retitled this revision from "[clang-tidy] Add check 
'misc-replace-memcpy'" to "[clang-tidy] Add check 'modernize-use-algorithm'".
JDevlieghere updated the summary for this revision.
JDevlieghere set the repository for this revision to rL LLVM.
JDevlieghere updated this revision to Diff 66247.
JDevlieghere added a comment.

- Addressed concerns raised by Etienne Bergeron
- Show warning when using void pointers but don't replace
- Don't make replacement when destination is const
- Don't make replacement when types are not compatible


Repository:
  rL LLVM

https://reviews.llvm.org/D22725

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseAlgorithmCheck.cpp
  clang-tidy/modernize/UseAlgorithmCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-algorithm.rst
  test/clang-tidy/modernize-use-algorithm.cpp

Index: test/clang-tidy/modernize-use-algorithm.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-algorithm.cpp
@@ -0,0 +1,50 @@
+// RUN: %check_clang_tidy %s modernize-use-algorithm %t
+
+// CHECK-FIXES: #include 
+
+namespace std {
+typedef unsigned int size_t;
+void *memcpy(void *dest, const void *src, std::size_t count);
+void *memset(void *dest, int ch, std::size_t count);
+
+template 
+OutputIt copy(InputIt first, InputIt last, OutputIt d_first);
+
+template 
+OutputIt move(InputIt first, InputIt last, OutputIt d_first);
+
+template 
+void fill(ForwardIt first, ForwardIt last, const T &value);
+}
+
+void a() {
+  char foo[] = "foo", bar[3];
+  std::memcpy(bar, foo, sizeof bar);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::copy instead of memcpy [modernize-use-algorithm]
+  // CHECK-FIXES: std::copy(foo, foo + sizeof bar, bar);
+
+  void* baz = bar;
+  std::memcpy(baz, foo, sizeof bar);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::copy instead of memcpy [modernize-use-algorithm]
+
+  std::copy(foo, foo + sizeof bar, bar);
+}
+
+void b() {
+  char foo[] = "foobar";
+  std::memset(foo, 'a', 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::fill instead of memset [modernize-use-algorithm]
+  // CHECK-FIXES: std::fill(foo, foo + 3, 'a');
+
+  std::memset(foo, 1, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::fill instead of memset [modernize-use-algorithm]
+
+  std::fill(foo, foo + 2, 'a');
+}
+
+#define MEMCPY(dest, src) std::memcpy((dest), (src), sizeof(dest))
+void c() {
+  char foo[] = "foo", bar[3];
+  MEMCPY(bar, foo);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Use std::copy instead of memcpy [modernize-use-algorithm]
+}
Index: docs/clang-tidy/checks/modernize-use-algorithm.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-algorithm.rst
@@ -0,0 +1,37 @@
+.. title:: clang-tidy - modernize-use-algorithm
+
+modernize-use-algorithm
+===
+
+Replaces calls to ``memcpy`` and ``memset`` with ``std::copy``, and
+``std::fill`` respectively. The advantages of using these algorithm functions
+is that they are at least as efficient, more general and type-aware.
+
+Furthermore, by using the algorithms the types remain intact as opposed to
+being discarded by the C-style functions. This allows the implementation to
+make use use of type information to further optimize. One example of such
+optimization is taking advantage of 64-bit alignment when copying an array of
+``std::uint64_t``.
+
+memcpy
+--
+
+.. code:: c++
+
+std::memcpy(dest, source, sizeof dest);
+
+// transforms to:
+
+std::copy(source, source + sizeof dest, dest);
+
+memset
+--
+
+.. code:: c++
+
+std::memset(dest, ch, count);
+
+// transforms to:
+
+std::fill(dest, dest + count, ch)
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -105,6 +105,7 @@
modernize-shrink-to-fit
modernize-use-auto
modernize-use-bool-literals
+   modernize-use-algorithm
modernize-use-default
modernize-use-emplace
modernize-use-nullptr
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -69,6 +69,12 @@
 
   Flags classes where some, but not all, special member functions are user-defined.
 
+- New `modernize-use-algorithm
+  `_ check
+
+  Replaces calls to ``memcpy`` and ``memset`` with their respective algorithm
+  counterparts ``std::copy`` and ``std::fill``.
+
 Improvements to include-fixer
 -
 
Index: clang-tidy/modernize/UseAlgorithmCheck.h
===
--- /dev/null
+++ clang-tidy/modernize

r277307 - Add more gcc compatibility names to clang's cpuid.h

2016-07-31 Thread Dimitry Andric via cfe-commits
Author: dim
Date: Sun Jul 31 15:23:23 2016
New Revision: 277307

URL: http://llvm.org/viewvc/llvm-project?rev=277307&view=rev
Log:
Add more gcc compatibility names to clang's cpuid.h

Summary:
Some cpuid bit defines are named slightly different from how gcc's
cpuid.h calls them.

Define a few more compatibility names to appease software built for gcc:

* `bit_PCLMUL`  alias of `bit_PCLMULQDQ`
* `bit_SSE4_1`  alias of `bit_SSE41`
* `bit_SSE4_2`  alias of `bit_SSE42`
* `bit_AES` alias of `bit_AESNI`
* `bit_CMPXCHG8B`   alias of `bit_CX8`

While here, add the misssing 29th bit, `bit_F16C` (which is how gcc
calls this bit).

Reviewers: joerg, rsmith

Subscribers: bruno, cfe-commits

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

Modified:
cfe/trunk/lib/Headers/cpuid.h

Modified: cfe/trunk/lib/Headers/cpuid.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/cpuid.h?rev=277307&r1=277306&r2=277307&view=diff
==
--- cfe/trunk/lib/Headers/cpuid.h (original)
+++ cfe/trunk/lib/Headers/cpuid.h Sun Jul 31 15:23:23 2016
@@ -82,6 +82,7 @@
 /* Features in %ecx for level 1 */
 #define bit_SSE30x0001
 #define bit_PCLMULQDQ   0x0002
+#define bit_PCLMUL  bit_PCLMULQDQ   /* for gcc compat */
 #define bit_DTES64  0x0004
 #define bit_MONITOR 0x0008
 #define bit_DSCPL   0x0010
@@ -98,15 +99,19 @@
 #define bit_PCID0x0002
 #define bit_DCA 0x0004
 #define bit_SSE41   0x0008
+#define bit_SSE4_1  bit_SSE41   /* for gcc compat */
 #define bit_SSE42   0x0010
+#define bit_SSE4_2  bit_SSE42   /* for gcc compat */
 #define bit_x2APIC  0x0020
 #define bit_MOVBE   0x0040
 #define bit_POPCNT  0x0080
 #define bit_TSCDeadline 0x0100
 #define bit_AESNI   0x0200
+#define bit_AES bit_AESNI   /* for gcc compat */
 #define bit_XSAVE   0x0400
 #define bit_OSXSAVE 0x0800
 #define bit_AVX 0x1000
+#define bit_F16C0x2000
 #define bit_RDRND   0x4000
 
 /* Features in %edx for level 1 */
@@ -119,6 +124,7 @@
 #define bit_PAE 0x0040
 #define bit_MCE 0x0080
 #define bit_CX8 0x0100
+#define bit_CMPXCHG8B   bit_CX8 /* for gcc compat */
 #define bit_APIC0x0200
 #define bit_SEP 0x0800
 #define bit_MTRR0x1000
@@ -133,7 +139,7 @@
 #define bit_ACPI0x0040
 #define bit_MMX 0x0080
 #define bit_FXSR0x0100
-#define bit_FXSAVE  bit_FXSR/* for gcc compat */
+#define bit_FXSAVE  bit_FXSR/* for gcc compat */
 #define bit_SSE 0x0200
 #define bit_SSE20x0400
 #define bit_SS  0x0800


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


Re: [PATCH] D22010: Add more gcc compatibility names to clang's cpuid.h

2016-07-31 Thread Dimitry Andric via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277307: Add more gcc compatibility names to clang's cpuid.h 
(authored by dim).

Changed prior to commit:
  https://reviews.llvm.org/D22010?vs=62781&id=66250#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22010

Files:
  cfe/trunk/lib/Headers/cpuid.h

Index: cfe/trunk/lib/Headers/cpuid.h
===
--- cfe/trunk/lib/Headers/cpuid.h
+++ cfe/trunk/lib/Headers/cpuid.h
@@ -82,6 +82,7 @@
 /* Features in %ecx for level 1 */
 #define bit_SSE30x0001
 #define bit_PCLMULQDQ   0x0002
+#define bit_PCLMUL  bit_PCLMULQDQ   /* for gcc compat */
 #define bit_DTES64  0x0004
 #define bit_MONITOR 0x0008
 #define bit_DSCPL   0x0010
@@ -98,15 +99,19 @@
 #define bit_PCID0x0002
 #define bit_DCA 0x0004
 #define bit_SSE41   0x0008
+#define bit_SSE4_1  bit_SSE41   /* for gcc compat */
 #define bit_SSE42   0x0010
+#define bit_SSE4_2  bit_SSE42   /* for gcc compat */
 #define bit_x2APIC  0x0020
 #define bit_MOVBE   0x0040
 #define bit_POPCNT  0x0080
 #define bit_TSCDeadline 0x0100
 #define bit_AESNI   0x0200
+#define bit_AES bit_AESNI   /* for gcc compat */
 #define bit_XSAVE   0x0400
 #define bit_OSXSAVE 0x0800
 #define bit_AVX 0x1000
+#define bit_F16C0x2000
 #define bit_RDRND   0x4000
 
 /* Features in %edx for level 1 */
@@ -119,6 +124,7 @@
 #define bit_PAE 0x0040
 #define bit_MCE 0x0080
 #define bit_CX8 0x0100
+#define bit_CMPXCHG8B   bit_CX8 /* for gcc compat */
 #define bit_APIC0x0200
 #define bit_SEP 0x0800
 #define bit_MTRR0x1000
@@ -133,7 +139,7 @@
 #define bit_ACPI0x0040
 #define bit_MMX 0x0080
 #define bit_FXSR0x0100
-#define bit_FXSAVE  bit_FXSR/* for gcc compat */
+#define bit_FXSAVE  bit_FXSR/* for gcc compat */
 #define bit_SSE 0x0200
 #define bit_SSE20x0400
 #define bit_SS  0x0800


Index: cfe/trunk/lib/Headers/cpuid.h
===
--- cfe/trunk/lib/Headers/cpuid.h
+++ cfe/trunk/lib/Headers/cpuid.h
@@ -82,6 +82,7 @@
 /* Features in %ecx for level 1 */
 #define bit_SSE30x0001
 #define bit_PCLMULQDQ   0x0002
+#define bit_PCLMUL  bit_PCLMULQDQ   /* for gcc compat */
 #define bit_DTES64  0x0004
 #define bit_MONITOR 0x0008
 #define bit_DSCPL   0x0010
@@ -98,15 +99,19 @@
 #define bit_PCID0x0002
 #define bit_DCA 0x0004
 #define bit_SSE41   0x0008
+#define bit_SSE4_1  bit_SSE41   /* for gcc compat */
 #define bit_SSE42   0x0010
+#define bit_SSE4_2  bit_SSE42   /* for gcc compat */
 #define bit_x2APIC  0x0020
 #define bit_MOVBE   0x0040
 #define bit_POPCNT  0x0080
 #define bit_TSCDeadline 0x0100
 #define bit_AESNI   0x0200
+#define bit_AES bit_AESNI   /* for gcc compat */
 #define bit_XSAVE   0x0400
 #define bit_OSXSAVE 0x0800
 #define bit_AVX 0x1000
+#define bit_F16C0x2000
 #define bit_RDRND   0x4000
 
 /* Features in %edx for level 1 */
@@ -119,6 +124,7 @@
 #define bit_PAE 0x0040
 #define bit_MCE 0x0080
 #define bit_CX8 0x0100
+#define bit_CMPXCHG8B   bit_CX8 /* for gcc compat */
 #define bit_APIC0x0200
 #define bit_SEP 0x0800
 #define bit_MTRR0x1000
@@ -133,7 +139,7 @@
 #define bit_ACPI0x0040
 #define bit_MMX 0x0080
 #define bit_FXSR0x0100
-#define bit_FXSAVE  bit_FXSR/* for gcc compat */
+#define bit_FXSAVE  bit_FXSR/* for gcc compat */
 #define bit_SSE 0x0200
 #define bit_SSE20x0400
 #define bit_SS  0x0800
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r277307 - Add more gcc compatibility names to clang's cpuid.h

2016-07-31 Thread Dimitry Andric via cfe-commits
Hi Hans,

I would like to merge this one to release_39, since it fixes a few third party 
programs using cpuid.h, and expecting gcc-compatible CPUID bit macros.

-Dimitry

> On 31 Jul 2016, at 22:23, Dimitry Andric via cfe-commits 
>  wrote:
> 
> Author: dim
> Date: Sun Jul 31 15:23:23 2016
> New Revision: 277307
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=277307&view=rev
> Log:
> Add more gcc compatibility names to clang's cpuid.h
> 
> Summary:
> Some cpuid bit defines are named slightly different from how gcc's
> cpuid.h calls them.
> 
> Define a few more compatibility names to appease software built for gcc:
> 
> * `bit_PCLMUL`  alias of `bit_PCLMULQDQ`
> * `bit_SSE4_1`  alias of `bit_SSE41`
> * `bit_SSE4_2`  alias of `bit_SSE42`
> * `bit_AES` alias of `bit_AESNI`
> * `bit_CMPXCHG8B`   alias of `bit_CX8`
> 
> While here, add the misssing 29th bit, `bit_F16C` (which is how gcc
> calls this bit).
> 
> Reviewers: joerg, rsmith
> 
> Subscribers: bruno, cfe-commits
> 
> Differential Revision: https://reviews.llvm.org/D22010
> 
> Modified:
>cfe/trunk/lib/Headers/cpuid.h
> 
> Modified: cfe/trunk/lib/Headers/cpuid.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/cpuid.h?rev=277307&r1=277306&r2=277307&view=diff
> ==
> --- cfe/trunk/lib/Headers/cpuid.h (original)
> +++ cfe/trunk/lib/Headers/cpuid.h Sun Jul 31 15:23:23 2016
> @@ -82,6 +82,7 @@
> /* Features in %ecx for level 1 */
> #define bit_SSE30x0001
> #define bit_PCLMULQDQ   0x0002
> +#define bit_PCLMUL  bit_PCLMULQDQ   /* for gcc compat */
> #define bit_DTES64  0x0004
> #define bit_MONITOR 0x0008
> #define bit_DSCPL   0x0010
> @@ -98,15 +99,19 @@
> #define bit_PCID0x0002
> #define bit_DCA 0x0004
> #define bit_SSE41   0x0008
> +#define bit_SSE4_1  bit_SSE41   /* for gcc compat */
> #define bit_SSE42   0x0010
> +#define bit_SSE4_2  bit_SSE42   /* for gcc compat */
> #define bit_x2APIC  0x0020
> #define bit_MOVBE   0x0040
> #define bit_POPCNT  0x0080
> #define bit_TSCDeadline 0x0100
> #define bit_AESNI   0x0200
> +#define bit_AES bit_AESNI   /* for gcc compat */
> #define bit_XSAVE   0x0400
> #define bit_OSXSAVE 0x0800
> #define bit_AVX 0x1000
> +#define bit_F16C0x2000
> #define bit_RDRND   0x4000
> 
> /* Features in %edx for level 1 */
> @@ -119,6 +124,7 @@
> #define bit_PAE 0x0040
> #define bit_MCE 0x0080
> #define bit_CX8 0x0100
> +#define bit_CMPXCHG8B   bit_CX8 /* for gcc compat */
> #define bit_APIC0x0200
> #define bit_SEP 0x0800
> #define bit_MTRR0x1000
> @@ -133,7 +139,7 @@
> #define bit_ACPI0x0040
> #define bit_MMX 0x0080
> #define bit_FXSR0x0100
> -#define bit_FXSAVE  bit_FXSR/* for gcc compat */
> +#define bit_FXSAVE  bit_FXSR/* for gcc compat */
> #define bit_SSE 0x0200
> #define bit_SSE20x0400
> #define bit_SS  0x0800
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits



signature.asc
Description: Message signed with OpenPGP using GPGMail
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22725: [clang-tidy] Add check 'modernize-use-algorithm'

2016-07-31 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

I see you solved the void and conmpatible types problems. Excellent!

Can you post a patch with changes after running LLVM? I would wait for Alex or 
Aaron to accept it.



Comment at: clang-tidy/modernize/UseAlgorithmCheck.cpp:58-60
@@ +57,5 @@
+
+  for (const auto &KeyValue :
+   std::vector>(
+   {{"memcpy", "std::copy"}, {"memset", "std::fill"}})) {
+Replacements.insert(KeyValue);

Try just initializer list instead of creating vector here.
Just 
for (const auto &keyValue : {std::make_pair("memcpy", "std::copy"), {"memset", 
"std::fill"}}

You just have to specify the type of the first argument and it will try to 
convert each next to it.


Comment at: clang-tidy/modernize/UseAlgorithmCheck.cpp:98-99
@@ +97,4 @@
+  const auto it = Replacements.find(MatchedName);
+  if (it == Replacements.end())
+return;
+  const auto ReplacedName = it->second;

this should not happen. You can change it to assert


Comment at: clang-tidy/modernize/UseAlgorithmCheck.cpp:139
@@ +138,3 @@
+// Cannot do pointer arithmetic on void type.
+if (getStrippedType(Arg1Type)->isVoidType())
+  return;

Would it be the same to check here for the first argument instead of second?
So then you could take this if before the if(MatchedName == "memset")


Comment at: docs/clang-tidy/checks/modernize-use-algorithm.rst:37
@@ +36,2 @@
+std::fill(dest, dest + count, ch)
+

You should add 2 notes here
1. The check runs just with C++.
2. There are some rare cases that require adding parens (and put example), so 
the check could right now generate wrong output.
 (which is something that I would not require to have, but it is good to leave 
not about it in documentation)

Also leave Fixit comment in the check.


Repository:
  rL LLVM

https://reviews.llvm.org/D22725



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


[PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-07-31 Thread Erik Pilkington via cfe-commits
erik.pilkington created this revision.
erik.pilkington added reviewers: manmanren, dexonsmith, dcoughlin.
erik.pilkington added a subscriber: cfe-commits.

This patch implements support for diagnostics for @available violations. This 
is done with a traversal of the AST after semantic analysis of a function where 
a partially available (based on availability attributes) use of a declaration 
is found. For example:

```
  if (@available(macos 10.12, *))
fn_10_12();
  else
fn_10_12(); // clang now emits a warning here
```

This patch also treats both branches of `if (@available(...))` checks as begin 
protected; being able to `goto` into them would break this feature. Also, 
`-Wpartial-availability` is now an alias of `-Wunguarded-availability`.

Up next is a patch to implement clang CodeGen support for 
`ObjCAvailabilityCheckExpr`, and another to provide fixits to suggest using 
@available.

This patch is part of a series that implements the feature I proposed here:
http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html


https://reviews.llvm.org/D23003

Files:
  include/clang/AST/Stmt.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/AST/Stmt.cpp
  lib/Sema/JumpDiagnostics.cpp
  lib/Sema/ScopeInfo.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  test/Sema/attr-availability.c
  test/SemaObjC/attr-availability.m
  test/SemaObjC/property-deprecated-warning.m
  test/SemaObjC/unguarded-availability.m

Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -0,0 +1,97 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fsyntax-only -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -DOBJCPP -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fsyntax-only -verify %s
+
+#define AVAILABLE_10_11 __attribute__((availability(macos, introduced = 10.11)))
+#define AVAILABLE_10_12 __attribute__((availability(macos, introduced = 10.12)))
+
+int func_10_11() AVAILABLE_10_11; // expected-note 3 {{'func_10_11' has been explicitly marked partial here}}
+
+int func_10_12() AVAILABLE_10_12; // expected-note 2 {{'func_10_12' has been explicitly marked partial here}}
+
+void use_func() {
+  func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *))
+func_10_11();
+  else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+}
+
+void defn_10_11() AVAILABLE_10_11;
+
+void defn_10_11() {
+  func_10_11();
+}
+
+void nested_ifs() {
+  if (@available(macos 10.12, *)) {
+if (@available(macos 10.10, *)) {
+  func_10_12();
+} else {
+  func_10_12();
+}
+  } else {
+func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
+  }
+}
+
+void star_case() {
+  if (@available(ios 9, *)) // expected-warning{{using '*' case here, platform macos is not accounted for}}
+func_10_11();
+  else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+}
+
+typedef int int_10_11 AVAILABLE_10_11; // expected-note {{'int_10_11' has been explicitly marked partial here}}
+typedef int int_10_12 AVAILABLE_10_12; // expected-note {{'int_10_12' has been explicitly marked partial here}}
+
+void use_typedef() {
+  int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}}
+}
+
+__attribute__((objc_root_class))
+AVAILABLE_10_11 @interface Class_10_11 {
+  int_10_11 foo;
+  int_10_12 bar; // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}}
+}
+- (void)method1;
+- (void)method2;
+@end
+
+@implementation Class_10_11
+- (void) method1 {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
+}
+
+- (void)method2 AVAILABLE_10_12 {
+  func_10_12();
+}
+
+@end
+
+int protected_scope() {
+  if (@available(macos 10.20, *)) { // expected-note 2 {{jump enters controlled statement of if available}}
+  label1:
+return 0;
+  } else {
+  label2:
+goto label1; // expected-error{{cannot jump from this goto statement to its label}}
+  }
+
+  goto label2; // expected-error{

Re: [PATCH] D22514: CloneDetection now respects statement specific data when searching for clones.

2016-07-31 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 66261.
teemperor added a comment.

- Added typedef for the contents of the data vector.
- Fixed that StmtDataCollector isn't visiting all parent classes of a statement.
- Removed 'test-' prefix from test files.
- Fixed the other problems as pointed out by Artem (Thanks!)
- Added performance remark to the qualified name strings in the data vectors.

I'm now falling back to the ConstStmtVisitor for visiting the parent statements 
(see the `DEF_ADD_DATA` macro) which is probably the best fix for the visitor 
problem.

clang's binary size increases with this patch to 32890440 bytes from 32863664 
bytes (+26 KB).

I've kept the long qualified name strings in the data vectors in for now 
because that's just a performance optimization. Using the pointer values would 
make the code non-deterministic and breaks cross-TU support and better 
solutions are probably out of scope for this patch. I've added a remark that we 
should fix this when we look into performance optimizations.


https://reviews.llvm.org/D22514

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  test/Analysis/copypaste/asm.cpp
  test/Analysis/copypaste/attributes.cpp
  test/Analysis/copypaste/call.cpp
  test/Analysis/copypaste/catch.cpp
  test/Analysis/copypaste/delete.cpp
  test/Analysis/copypaste/dependent-exist.cpp
  test/Analysis/copypaste/expr-types.cpp
  test/Analysis/copypaste/false-positives.cpp
  test/Analysis/copypaste/fold.cpp
  test/Analysis/copypaste/function-try-block.cpp
  test/Analysis/copypaste/functions.cpp
  test/Analysis/copypaste/generic.c
  test/Analysis/copypaste/labels.cpp
  test/Analysis/copypaste/lambda.cpp

Index: test/Analysis/copypaste/lambda.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/lambda.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+void foo1(int a, long b) {
+  auto l = [a, b](){};
+}
+
+void foo2(int a, long b) {
+  auto l = [&a, b](){};
+}
+
+void foo3(int a, long b) {
+  auto l = [a](){};
+}
+
+void foo4(int a, long b) {
+  auto l = [=](){};
+}
+
+void foo5(int a, long b) {
+  auto l = [&](){};
+}
+
Index: test/Analysis/copypaste/labels.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/labels.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -analyze -std=gnu++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+
+bool foo1(int x) {
+  start:
+  if (x != 3) {
+++x;
+void *ptr = &&start;
+goto start;
+  }
+  end:
+  return false;
+}
+
+// Targeting a different label with the address-of-label operator.
+bool foo2(int x) {
+  start:
+  if (x != 3) {
+++x;
+void *ptr = &&end;
+goto start;
+  }
+  end:
+  return false;
+}
+
+// Different target label in goto
+bool foo3(int x) {
+  start:
+  if (x != 3) {
+++x;
+void *ptr = &&start;
+goto end;
+  }
+  end:
+  return false;
+}
+
+// FIXME: Can't detect same algorithm as in foo1 but with different label names.
+bool foo4(int x) {
+  foo:
+  if (x != 3) {
+++x;
+void *ptr = &&foo;
+goto foo;
+  }
+  end:
+  return false;
+}
Index: test/Analysis/copypaste/generic.c
===
--- /dev/null
+++ test/Analysis/copypaste/generic.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -analyze -std=c11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+int global;
+
+int foo1() {
+  if (global > 0)
+return 0;
+  else if (global < 0)
+return _Generic(global, double: 1, float: 2, default: 3);
+  return 1;
+}
+
+// Different associated type (int instead of float)
+int foo2() {
+  if (global > 0)
+return 0;
+  else if (global < 0)
+return _Generic(global, double: 1, int: 2, default: 4);
+  return 1;
+}
+
+// Different number of associated types.
+int foo3() {
+  if (global > 0)
+return 0;
+  else if (global < 0)
+return _Generic(global, double: 1, default: 4);
+  return 1;
+}
Index: test/Analysis/copypaste/functions.cpp
===
--- test/Analysis/copypaste/functions.cpp
+++ test/Analysis/copypaste/functions.cpp
@@ -20,6 +20,13 @@
 
 // Functions below are not clones and should not be reported.
 
+int min1(int a, int b) { // no-warning
+  log();
+  if (a < b)
+return a;
+  return b;
+}
+
 int foo(int a, int b) { // no-warning
   return a + b;
 }
Index: test/Analysis/copypaste/function-try-block.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/function-try-block.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -analyze -fcxx-exceptions -std=c++1z -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// Tests if function try blocks are correctly handled.
+
+void nonCompoundStmt1(int& x

Re: [PATCH] D22982: [CloneDetector] No longer reporting clones that don't have a common referenced variable pattern.

2016-07-31 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 66262.
teemperor added a comment.

- Fixed a few typos in the comments.
- Removed unnecessary `std::`.
- Added the new tests to functions.cpp instead of their own file.


https://reviews.llvm.org/D22982

Files:
  lib/Analysis/CloneDetection.cpp
  test/Analysis/copypaste/false-positives.cpp
  test/Analysis/copypaste/functions.cpp

Index: test/Analysis/copypaste/functions.cpp
===
--- test/Analysis/copypaste/functions.cpp
+++ test/Analysis/copypaste/functions.cpp
@@ -18,15 +18,24 @@
   return y;
 }
 
-// Functions below are not clones and should not be reported.
+// Different variable patterns, therefore different clones.
 
-int min1(int a, int b) { // no-warning
+int min(int x, int y) { // expected-warning{{Detected code clone.}}
   log();
-  if (a < b)
-return a;
-  return b;
+  if (y > x)
+return x;
+  return y;
+}
+
+int minClone(int x, int y) { // expected-note{{Related code clone is here.}}
+  log();
+  if (y > x)
+return x;
+  return y;
 }
 
+// Functions below are not clones and should not be reported.
+
 int foo(int a, int b) { // no-warning
   return a + b;
 }
Index: test/Analysis/copypaste/false-positives.cpp
===
--- test/Analysis/copypaste/false-positives.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
-
-// This test contains false-positive reports from the CloneChecker that need to
-// be fixed.
-
-void log();
-
-int max(int a, int b) { // expected-warning{{Detected code clone.}}
-  log();
-  if (a > b)
-return a;
-  return b;
-}
-
-// FIXME: Detect different variable patterns.
-int min2(int a, int b) { // expected-note{{Related code clone is here.}}
-  log();
-  if (b > a)
-return a;
-  return b;
-}
Index: lib/Analysis/CloneDetection.cpp
===
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -80,6 +80,102 @@
 SourceLocation StmtSequence::getEndLoc() const { return back()->getLocEnd(); }
 
 namespace {
+
+/// \brief Analyzes the pattern of the referenced variables in a statement.
+class VariablePattern {
+
+  /// \brief Describes an occurence of a variable reference in a statement.
+  struct VariableOccurence {
+/// The index of the associated VarDecl in the Variables vector.
+size_t KindID;
+
+VariableOccurence(size_t KindID) : KindID(KindID) {}
+  };
+
+  /// All occurences of referenced variables in the order of appearance.
+  std::vector Occurences;
+  /// List of referenced variables in the order of appearance.
+  /// Every item in this list is unique.
+  std::vector Variables;
+
+  /// \brief Adds a new variable referenced to this pattern.
+  /// \param VarDecl The declaration of the variable that is referenced.
+  void addVariableOccurence(const VarDecl *VarDecl) {
+// First check if we already reference this variable
+for (size_t KindIndex = 0; KindIndex < Variables.size(); ++KindIndex) {
+  if (Variables[KindIndex] == VarDecl) {
+// If yes, add a new occurence that points to the existing entry in
+// the Variables vector.
+Occurences.emplace_back(KindIndex);
+return;
+  }
+}
+// If this variable wasn't already referenced, add it to the list of
+// referenced variables and add a occurence that points to this new entry.
+Occurences.emplace_back(Variables.size());
+Variables.push_back(VarDecl);
+  }
+
+  /// \brief Adds each referenced variable from the given statement.
+  void addVariables(const Stmt *S) {
+// Sometimes we get a nullptr (such as from IfStmts which often have nullptr
+// children). We skip such statements as they don't reference any
+// variables.
+if (!S)
+  return;
+
+// Check if S is a reference to a variable. If yes, add it to the pattern.
+if (auto D = dyn_cast(S)) {
+  if (auto VD = dyn_cast(D->getDecl()->getCanonicalDecl()))
+addVariableOccurence(VD);
+}
+
+// Recursively check all children of the given statement.
+for (const Stmt *Child : S->children()) {
+  addVariables(Child);
+}
+  }
+
+public:
+  /// \brief Creates an VariablePattern object with information about the given
+  ///StmtSequence.
+  VariablePattern(const StmtSequence &Sequence) {
+for (const Stmt *S : Sequence)
+  addVariables(S);
+  }
+
+  /// \brief Compares this pattern with the given one.
+  /// \param Other The given VariablePattern to compare with.
+  /// \return Returns true if and only if the references variables in this
+  /// object follow the same pattern than the ones in the given
+  /// VariablePattern.
+  ///
+  /// For example, the following statements all have the same pattern:
+  ///
+  ///   if (a < b) return a; return b;
+  ///   if (x < y) return x; return y;

Re: [PATCH] D22982: [CloneDetector] No longer reporting clones that don't have a common referenced variable pattern.

2016-07-31 Thread Raphael Isemann via cfe-commits
teemperor marked 2 inline comments as done.
teemperor added a comment.

https://reviews.llvm.org/D22982



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


Re: [PATCH] D22982: [CloneDetector] No longer reporting clones that don't have a common referenced variable pattern.

2016-07-31 Thread Raphael Isemann via cfe-commits
teemperor added a comment.

I've deleted false-positives.cpp because all false-positives in there are now 
resolved and the test did no longer serve a purpose. We could leave the test 
file in there, but I think new false-positives either belong to an existing 
test category or deserve their own named test file (e.g. macros.cpp would 
contain tests for macros and related false-positives with a FIXME remark). 
Opinions?


https://reviews.llvm.org/D22982



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


RE: [PATCH] D20979: [OpenCL] Use function metadata to represent kernel attributes

2016-07-31 Thread Pan Xiuli via cfe-commits
Hi Sam,

I am now using llvm39 to enable our opencl driver, but I found this patch broke 
the spir target as well.
The opencl.kernels metadata is required by spir spec. I think we should keep 
the old code for spir target.

Thanks
Xiuli

-Original Message-
From: Yaxun Liu [mailto:yaxun@amd.com] 
Sent: Wednesday, June 22, 2016 11:04 PM
To: yaxun@amd.com; xiuli...@outlook.com; anastasia.stul...@arm.com; 
alexey.ba...@intel.com
Cc: thomas.stell...@amd.com; cfe-commits@lists.llvm.org
Subject: Re: [PATCH] D20979: [OpenCL] Use function metadata to represent kernel 
attributes

This revision was automatically updated to reflect the committed changes.
Closed by commit rL273425: [OpenCL] Use function metadata to represent kernel 
attributes (authored by yaxunl).

Changed prior to commit:
  http://reviews.llvm.org/D20979?vs=60545&id=61555#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20979

Files:
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
  cfe/trunk/test/CodeGenOpenCL/kernel-attributes.cl
  cfe/trunk/test/CodeGenOpenCL/kernel-metadata.cl

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


Re: [PATCH] D22900: Revert r244207 - Mark calls in thunk functions as tail-call optimization

2016-07-31 Thread Gerolf Hoflehner via cfe-commits

> On Jul 31, 2016, at 1:46 AM, Amjad Aboud  wrote:
> 
> aaboud added a comment.
> 
>> ISTM that the DWARF spec intended such thunks to be encoded as 
>> `DW_AT_trampoline`.  That seems more appropriate than relying on codegen 
>> emitting a tailcall.  This way the debugger can make the policy decision of 
>> whether or not thunks should show up in the backtrace.
> 
>> 
> 
>> In any case, correctness must always trump all else.  Reverting to green 
>> should take precedence over a QoI bug like PR24235.
> 
> 
> I agree to the revert, though I am not sure about the new test, it looks too 
> complected, especially the command line.

An app crashed somewhere because it loaded a garbage value from the stack. To 
show that problem the test is.a little longer than it would be if we only 
wanted to check " no tail + byval “. 
> I will let David decide on accepting that test or ask for improvement.
> 
> Regards,
> Amjad
> 
> 
> https://reviews.llvm.org/D22900
> 
> 
> 

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


Re: [PATCH] D22900: Revert r244207 - Mark calls in thunk functions as tail-call optimization

2016-07-31 Thread Gerolf Hoflehner via cfe-commits

> On Jul 31, 2016, at 12:11 AM, Amjad Aboud  wrote:
> 
> aaboud added a comment.
> 
> Reverting https://reviews.llvm.org/rL244207, would be fine if we assure that 
> PR24235, is fixed in another way.

I think it is inappropriate for anyone who introduced a bug to condition a 
revert on a correct implementation on his or her feature. 

> I added Reid who helped reviewing the original patch 
> https://reviews.llvm.org/D11476.
> 
> 
> https://reviews.llvm.org/D22900
> 
> 
> 

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


Re: [PATCH] D22666: Frontend: Fix mcount inlining bug

2016-07-31 Thread Honggyu Kim via cfe-commits
honggyu.kim updated the summary for this revision.
honggyu.kim updated this revision to Diff 66276.
honggyu.kim added a comment.

I've updated the testcase again it adds 2 more tests for -O2 and without -pg.
Please have a look at it.

  $ llvm-lit mcount.c
  -- Testing: 1 tests, 1 threads --
  PASS: Clang :: CodeGen/mcount.c (1 of 1)
  Testing Time: 32.61s
Expected Passes: 1


https://reviews.llvm.org/D22666

Files:
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGen/mcount.c

Index: test/CodeGen/mcount.c
===
--- test/CodeGen/mcount.c
+++ test/CodeGen/mcount.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -pg -triple i386-unknown-unknown -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -pg -triple i386-unknown-unknown -emit-llvm -O2 -o - %s | 
FileCheck %s
 // RUN: %clang_cc1 -pg -triple powerpc-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefix=CHECK-PREFIXED %s
 // RUN: %clang_cc1 -pg -triple powerpc64-unknown-gnu-linux -emit-llvm -o - %s 
| FileCheck -check-prefix=CHECK-PREFIXED %s
 // RUN: %clang_cc1 -pg -triple powerpc64le-unknown-gnu-linux -emit-llvm -o - 
%s | FileCheck -check-prefix=CHECK-PREFIXED %s
@@ -12,7 +13,20 @@
 // RUN: %clang_cc1 -pg -triple powerpc64le-netbsd -emit-llvm -o - %s | 
FileCheck -check-prefix=CHECK-PREFIXED %s
 // RUN: %clang_cc1 -pg -triple sparc-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
 // RUN: %clang_cc1 -pg -triple sparc64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
-void foo(void) {
-// CHECK: call void @mcount()
-// CHECK-PREFIXED: call void @_mcount()
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s -check-prefix=NO-MCOUNT
+
+int bar(void) {
+  return 0;
 }
+
+int foo(void) {
+  return bar();
+}
+
+int main(void) {
+  return foo();
+}
+
+// CHECK: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="mcount"{{.*}} }
+// CHECK-PREFIXED: attributes #{{[0-9]+}} = { 
{{.*}}"counting-function"="_mcount"{{.*}} }
+// NO-MCOUNT-NOT: attributes #{{[0-9]}} = { {{.*}}"counting-function"={{.*}} }
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -428,14 +428,6 @@
   EmitNounwindRuntimeCall(F, args);
 }
 
-void CodeGenFunction::EmitMCountInstrumentation() {
-  llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
-
-  llvm::Constant *MCountFn =
-CGM.CreateRuntimeFunction(FTy, getTarget().getMCountName());
-  EmitNounwindRuntimeCall(MCountFn);
-}
-
 // OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
 // information in the program executable. The argument information stored
 // includes the argument name, its type, the address and access qualifiers 
used.
@@ -794,8 +786,12 @@
   if (ShouldInstrumentFunction())
 EmitFunctionInstrumentation("__cyg_profile_func_enter");
 
+  // Since emitting the mcount call here impacts optimizations such as function
+  // inlining, we just add an attribute to insert a mcount call in backend.
+  // The attribute "counting-function" is set to mcount function name which is
+  // architecture dependent.
   if (CGM.getCodeGenOpts().InstrumentForProfiling)
-EmitMCountInstrumentation();
+Fn->addFnAttr("counting-function", getTarget().getMCountName());
 
   if (RetTy->isVoidType()) {
 // Void type; nothing to return.


Index: test/CodeGen/mcount.c
===
--- test/CodeGen/mcount.c
+++ test/CodeGen/mcount.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -pg -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -pg -triple i386-unknown-unknown -emit-llvm -O2 -o - %s | FileCheck %s
 // RUN: %clang_cc1 -pg -triple powerpc-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-PREFIXED %s
 // RUN: %clang_cc1 -pg -triple powerpc64-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-PREFIXED %s
 // RUN: %clang_cc1 -pg -triple powerpc64le-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-PREFIXED %s
@@ -12,7 +13,20 @@
 // RUN: %clang_cc1 -pg -triple powerpc64le-netbsd -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-PREFIXED %s
 // RUN: %clang_cc1 -pg -triple sparc-netbsd -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-PREFIXED %s
 // RUN: %clang_cc1 -pg -triple sparc64-netbsd -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-PREFIXED %s
-void foo(void) {
-// CHECK: call void @mcount()
-// CHECK-PREFIXED: call void @_mcount()
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s -check-prefix=NO-MCOUNT
+
+int bar(void) {
+  return 0;
 }
+
+int foo(void) {
+  return bar();
+}
+
+int main(void) {
+  return foo();
+}
+
+// CHECK: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="mcount"{{.*}} }
+// CHECK-PREFIXED: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="_mcount"{{.*}} }
+// NO-MCOUNT-NOT: attributes #{{[0-