[libcxx] r313694 - [libc++] Replace __sync_* functions with __libcpp_atomic_* functions

2017-09-19 Thread Weiming Zhao via cfe-commits
Author: weimingz
Date: Tue Sep 19 16:18:03 2017
New Revision: 313694

URL: http://llvm.org/viewvc/llvm-project?rev=313694&view=rev
Log:
[libc++] Replace __sync_* functions with __libcpp_atomic_* functions

Summary:
This patch replaces __sync_* with __libcpp_atomic_* and adds a wrapper
function for __atomic_exchange to support _LIBCPP_HAS_NO_THREADS.

Reviewers: EricWF, jroelofs, mclow.lists, compnerd

Reviewed By: EricWF, compnerd

Subscribers: compnerd, efriedma, cfe-commits, joerg, llvm-commits

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

Modified:
libcxx/trunk/src/exception.cpp
libcxx/trunk/src/include/atomic_support.h
libcxx/trunk/src/include/refstring.h
libcxx/trunk/src/locale.cpp
libcxx/trunk/src/new.cpp
libcxx/trunk/src/support/runtime/exception_fallback.ipp
libcxx/trunk/src/support/runtime/new_handler_fallback.ipp

Modified: libcxx/trunk/src/exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/exception.cpp?rev=313694&r1=313693&r2=313694&view=diff
==
--- libcxx/trunk/src/exception.cpp (original)
+++ libcxx/trunk/src/exception.cpp Tue Sep 19 16:18:03 2017
@@ -31,6 +31,7 @@
 #include "support/runtime/exception_glibcxx.ipp"
 #include "support/runtime/exception_pointer_glibcxx.ipp"
 #else
+#include "include/atomic_support.h"
 #include "support/runtime/exception_fallback.ipp"
 #include "support/runtime/exception_pointer_unimplemented.ipp"
 #endif

Modified: libcxx/trunk/src/include/atomic_support.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/include/atomic_support.h?rev=313694&r1=313693&r2=313694&view=diff
==
--- libcxx/trunk/src/include/atomic_support.h (original)
+++ libcxx/trunk/src/include/atomic_support.h Tue Sep 19 16:18:03 2017
@@ -16,6 +16,7 @@
 #if defined(__clang__) && __has_builtin(__atomic_load_n) \
&& __has_builtin(__atomic_store_n)\
&& __has_builtin(__atomic_add_fetch)  \
+   && __has_builtin(__atomic_exchange_n) \
&& __has_builtin(__atomic_compare_exchange_n) \
&& defined(__ATOMIC_RELAXED)  \
&& defined(__ATOMIC_CONSUME)  \
@@ -84,6 +85,14 @@ _ValueType __libcpp_atomic_add(_ValueTyp
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY
+_ValueType __libcpp_atomic_exchange(_ValueType* __target,
+_ValueType __value, int __order = _AO_Seq)
+{
+return __atomic_exchange_n(__target, __value, __order);
+}
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY
 bool __libcpp_atomic_compare_exchange(_ValueType* __val,
 _ValueType* __expected, _ValueType __after,
 int __success_order = _AO_Seq,
@@ -136,6 +145,16 @@ _ValueType __libcpp_atomic_add(_ValueTyp
 }
 
 template 
+inline _LIBCPP_INLINE_VISIBILITY
+_ValueType __libcpp_atomic_exchange(_ValueType* __target,
+_ValueType __value, int __order = _AO_Seq)
+{
+_ValueType old = *__target;
+*__target = __value;
+return old;
+}
+
+template 
 inline _LIBCPP_INLINE_VISIBILITY
 bool __libcpp_atomic_compare_exchange(_ValueType* __val,
 _ValueType* __expected, _ValueType __after,

Modified: libcxx/trunk/src/include/refstring.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/include/refstring.h?rev=313694&r1=313693&r2=313694&view=diff
==
--- libcxx/trunk/src/include/refstring.h (original)
+++ libcxx/trunk/src/include/refstring.h Tue Sep 19 16:18:03 2017
@@ -18,6 +18,7 @@
 #include 
 #include 
 #endif
+#include "atomic_support.h"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -83,7 +84,7 @@ __libcpp_refstring::__libcpp_refstring(c
 : __imp_(s.__imp_)
 {
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
 }
 
 inline
@@ -92,10 +93,10 @@ __libcpp_refstring& __libcpp_refstring::
 struct _Rep_base *old_rep = rep_from_data(__imp_);
 __imp_ = s.__imp_;
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
 if (adjust_old_count)
 {
-if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
+if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0)
 {
 ::operator delete(old_rep);
 }
@@ -107,7 +108,7 @@ inline
 __libcpp_refstring::~__libcpp_refstring() {
 if (__uses_refcount()) {
 _Rep_base* rep = rep_from_data(__imp_);
-if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
+if (__libcpp_atomic_add(&rep->count, count_t(-1)) < 0) {
 ::operator delete(rep);
 }

Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-09-06 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

ping?


https://reviews.llvm.org/D17741



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


[libcxx] r307591 - [libc++] Refactoring __sync_* builtins; NFC

2017-07-10 Thread Weiming Zhao via cfe-commits
Author: weimingz
Date: Mon Jul 10 14:02:54 2017
New Revision: 307591

URL: http://llvm.org/viewvc/llvm-project?rev=307591&view=rev
Log:
[libc++] Refactoring __sync_* builtins; NFC

Summary: Wrap __sync_* builtins with __libcpp_ functions to facility future 
customizations as atomic operations are unavailable on some targets.

Reviewers: danalbert, EricWF, jroelofs

Subscribers: joerg, llvm-commits

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

Added:
libcxx/trunk/include/__atomic_support
Modified:
libcxx/trunk/include/__refstring
libcxx/trunk/src/locale.cpp
libcxx/trunk/src/support/runtime/exception_fallback.ipp
libcxx/trunk/src/support/runtime/new_handler_fallback.ipp

Added: libcxx/trunk/include/__atomic_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__atomic_support?rev=307591&view=auto
==
--- libcxx/trunk/include/__atomic_support (added)
+++ libcxx/trunk/include/__atomic_support Mon Jul 10 14:02:54 2017
@@ -0,0 +1,31 @@
+// -*- C++ -*-
+//=== __atomic_support 
-===//
+//
+// 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.
+//
+//===--===//
+
+#ifndef _LIBCPP___ATOMIC_SUPPORT
+#define _LIBCPP___ATOMIC_SUPPORT
+
+#include <__config>
+
+template
+T __libcpp_sync_add_and_fetch(T *ptr, T value) {
+  return __sync_add_and_fetch(ptr, value);
+}
+
+template
+T __libcpp_sync_fetch_and_add(T *ptr, T value) {
+  return __sync_fetch_and_add(ptr, value);
+}
+
+template
+T __libcpp_sync_lock_test_and_set(T *ptr, T value) {
+  return __sync_lock_test_and_set(ptr, value);
+}
+
+#endif //_LIBCPP___ATOMIC_SUPPORT

Modified: libcxx/trunk/include/__refstring
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__refstring?rev=307591&r1=307590&r2=307591&view=diff
==
--- libcxx/trunk/include/__refstring (original)
+++ libcxx/trunk/include/__refstring Mon Jul 10 14:02:54 2017
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include <__atomic_support>
 #ifdef __APPLE__
 #include 
 #include 
@@ -83,7 +84,7 @@ __libcpp_refstring::__libcpp_refstring(c
 : __imp_(s.__imp_)
 {
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
 }
 
 inline
@@ -92,10 +93,10 @@ __libcpp_refstring& __libcpp_refstring::
 struct _Rep_base *old_rep = rep_from_data(__imp_);
 __imp_ = s.__imp_;
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
 if (adjust_old_count)
 {
-if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
+if (__libcpp_sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
 {
 ::operator delete(old_rep);
 }
@@ -107,7 +108,7 @@ inline
 __libcpp_refstring::~__libcpp_refstring() {
 if (__uses_refcount()) {
 _Rep_base* rep = rep_from_data(__imp_);
-if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
+if (__libcpp_sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
 ::operator delete(rep);
 }
 }

Modified: libcxx/trunk/src/locale.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=307591&r1=307590&r2=307591&view=diff
==
--- libcxx/trunk/src/locale.cpp (original)
+++ libcxx/trunk/src/locale.cpp Mon Jul 10 14:02:54 2017
@@ -667,7 +667,7 @@ locale::id::__get()
 void
 locale::id::__init()
 {
-__id_ = __sync_add_and_fetch(&__next_id, 1);
+__id_ = __libcpp_sync_add_and_fetch(&__next_id, 1);
 }
 
 // template <> class collate_byname

Modified: libcxx/trunk/src/support/runtime/exception_fallback.ipp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_fallback.ipp?rev=307591&r1=307590&r2=307591&view=diff
==
--- libcxx/trunk/src/support/runtime/exception_fallback.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_fallback.ipp Mon Jul 10 14:02:54 
2017
@@ -9,6 +9,7 @@
 
//===--===//
 
 #include 
+#include <__atomic_support>
 
 namespace std {
 
@@ -20,13 +21,13 @@ _LIBCPP_SAFE_STATIC static std::unexpect
 unexpected_handler
 set_unexpected(unexpected_handler func) _NOEXCEPT
 {
-  return __sync_lock_test_and_set(&__unexpected_handler, func);
+  return __libcpp_sync_lock_test_and_set(&__unexpected_handler, func);
 }
 
 unexpected_handler
 get_u

[libcxx] r307593 - Revert "[libc++] Refactoring __sync_* builtins; NFC"

2017-07-10 Thread Weiming Zhao via cfe-commits
Author: weimingz
Date: Mon Jul 10 14:23:32 2017
New Revision: 307593

URL: http://llvm.org/viewvc/llvm-project?rev=307593&view=rev
Log:
Revert "[libc++] Refactoring __sync_* builtins; NFC"

This reverts commit 72ff8866bca49ee7d24c87673293b4ce88a039ec.

Removed:
libcxx/trunk/include/__atomic_support
Modified:
libcxx/trunk/include/__refstring
libcxx/trunk/src/locale.cpp
libcxx/trunk/src/support/runtime/exception_fallback.ipp
libcxx/trunk/src/support/runtime/new_handler_fallback.ipp

Removed: libcxx/trunk/include/__atomic_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__atomic_support?rev=307592&view=auto
==
--- libcxx/trunk/include/__atomic_support (original)
+++ libcxx/trunk/include/__atomic_support (removed)
@@ -1,31 +0,0 @@
-// -*- C++ -*-
-//=== __atomic_support 
-===//
-//
-// 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.
-//
-//===--===//
-
-#ifndef _LIBCPP___ATOMIC_SUPPORT
-#define _LIBCPP___ATOMIC_SUPPORT
-
-#include <__config>
-
-template
-T __libcpp_sync_add_and_fetch(T *ptr, T value) {
-  return __sync_add_and_fetch(ptr, value);
-}
-
-template
-T __libcpp_sync_fetch_and_add(T *ptr, T value) {
-  return __sync_fetch_and_add(ptr, value);
-}
-
-template
-T __libcpp_sync_lock_test_and_set(T *ptr, T value) {
-  return __sync_lock_test_and_set(ptr, value);
-}
-
-#endif //_LIBCPP___ATOMIC_SUPPORT

Modified: libcxx/trunk/include/__refstring
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__refstring?rev=307593&r1=307592&r2=307593&view=diff
==
--- libcxx/trunk/include/__refstring (original)
+++ libcxx/trunk/include/__refstring Mon Jul 10 14:23:32 2017
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include 
-#include <__atomic_support>
 #ifdef __APPLE__
 #include 
 #include 
@@ -84,7 +83,7 @@ __libcpp_refstring::__libcpp_refstring(c
 : __imp_(s.__imp_)
 {
 if (__uses_refcount())
-__libcpp_sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
 }
 
 inline
@@ -93,10 +92,10 @@ __libcpp_refstring& __libcpp_refstring::
 struct _Rep_base *old_rep = rep_from_data(__imp_);
 __imp_ = s.__imp_;
 if (__uses_refcount())
-__libcpp_sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
 if (adjust_old_count)
 {
-if (__libcpp_sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
+if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
 {
 ::operator delete(old_rep);
 }
@@ -108,7 +107,7 @@ inline
 __libcpp_refstring::~__libcpp_refstring() {
 if (__uses_refcount()) {
 _Rep_base* rep = rep_from_data(__imp_);
-if (__libcpp_sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
+if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
 ::operator delete(rep);
 }
 }

Modified: libcxx/trunk/src/locale.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=307593&r1=307592&r2=307593&view=diff
==
--- libcxx/trunk/src/locale.cpp (original)
+++ libcxx/trunk/src/locale.cpp Mon Jul 10 14:23:32 2017
@@ -667,7 +667,7 @@ locale::id::__get()
 void
 locale::id::__init()
 {
-__id_ = __libcpp_sync_add_and_fetch(&__next_id, 1);
+__id_ = __sync_add_and_fetch(&__next_id, 1);
 }
 
 // template <> class collate_byname

Modified: libcxx/trunk/src/support/runtime/exception_fallback.ipp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_fallback.ipp?rev=307593&r1=307592&r2=307593&view=diff
==
--- libcxx/trunk/src/support/runtime/exception_fallback.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_fallback.ipp Mon Jul 10 14:23:32 
2017
@@ -9,7 +9,6 @@
 
//===--===//
 
 #include 
-#include <__atomic_support>
 
 namespace std {
 
@@ -21,13 +20,13 @@ _LIBCPP_SAFE_STATIC static std::unexpect
 unexpected_handler
 set_unexpected(unexpected_handler func) _NOEXCEPT
 {
-  return __libcpp_sync_lock_test_and_set(&__unexpected_handler, func);
+  return __sync_lock_test_and_set(&__unexpected_handler, func);
 }
 
 unexpected_handler
 get_unexpected() _NOEXCEPT
 {
-  return __libcpp_sync_fetch_and_add(&__unexpected_handler, 
(unexpected_handler)0);
+  return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0);
 
 }
 
@@ -42,13 +41,14 

[libcxx] r307595 - [libc++] Refactoring __sync_* builtins; NFC (Reland)

2017-07-10 Thread Weiming Zhao via cfe-commits
Author: weimingz
Date: Mon Jul 10 14:37:35 2017
New Revision: 307595

URL: http://llvm.org/viewvc/llvm-project?rev=307595&view=rev
Log:
[libc++] Refactoring __sync_* builtins; NFC (Reland)

Summary: Wrap __sync_* builtins with __libcpp_ functions to facility future 
customizations as atomic operations are unavailable on some targets.

Reviewers: danalbert, EricWF, jroelofs

Subscribers: joerg, llvm-commits

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

Added:
libcxx/trunk/include/__atomic_support
Modified:
libcxx/trunk/include/__refstring
libcxx/trunk/src/locale.cpp
libcxx/trunk/src/support/runtime/exception_fallback.ipp
libcxx/trunk/src/support/runtime/new_handler_fallback.ipp

Added: libcxx/trunk/include/__atomic_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__atomic_support?rev=307595&view=auto
==
--- libcxx/trunk/include/__atomic_support (added)
+++ libcxx/trunk/include/__atomic_support Mon Jul 10 14:37:35 2017
@@ -0,0 +1,31 @@
+// -*- C++ -*-
+//=== __atomic_support 
-===//
+//
+// 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.
+//
+//===--===//
+
+#ifndef _LIBCPP___ATOMIC_SUPPORT
+#define _LIBCPP___ATOMIC_SUPPORT
+
+#include <__config>
+
+template
+T __libcpp_sync_add_and_fetch(T *ptr, T value) {
+  return __sync_add_and_fetch(ptr, value);
+}
+
+template
+T __libcpp_sync_fetch_and_add(T *ptr, T value) {
+  return __sync_fetch_and_add(ptr, value);
+}
+
+template
+T __libcpp_sync_lock_test_and_set(T *ptr, T value) {
+  return __sync_lock_test_and_set(ptr, value);
+}
+
+#endif //_LIBCPP___ATOMIC_SUPPORT

Modified: libcxx/trunk/include/__refstring
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__refstring?rev=307595&r1=307594&r2=307595&view=diff
==
--- libcxx/trunk/include/__refstring (original)
+++ libcxx/trunk/include/__refstring Mon Jul 10 14:37:35 2017
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include <__atomic_support>
 #ifdef __APPLE__
 #include 
 #include 
@@ -83,7 +84,7 @@ __libcpp_refstring::__libcpp_refstring(c
 : __imp_(s.__imp_)
 {
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
 }
 
 inline
@@ -92,10 +93,10 @@ __libcpp_refstring& __libcpp_refstring::
 struct _Rep_base *old_rep = rep_from_data(__imp_);
 __imp_ = s.__imp_;
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
 if (adjust_old_count)
 {
-if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
+if (__libcpp_sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
 {
 ::operator delete(old_rep);
 }
@@ -107,7 +108,7 @@ inline
 __libcpp_refstring::~__libcpp_refstring() {
 if (__uses_refcount()) {
 _Rep_base* rep = rep_from_data(__imp_);
-if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
+if (__libcpp_sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
 ::operator delete(rep);
 }
 }

Modified: libcxx/trunk/src/locale.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=307595&r1=307594&r2=307595&view=diff
==
--- libcxx/trunk/src/locale.cpp (original)
+++ libcxx/trunk/src/locale.cpp Mon Jul 10 14:37:35 2017
@@ -28,6 +28,7 @@
 #define _CTYPE_DISABLE_MACROS
 #endif
 #include "cwctype"
+#include "__atomic_support"
 #include "__sso_allocator"
 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
 #include "support/win32/locale_win32.h"
@@ -667,7 +668,7 @@ locale::id::__get()
 void
 locale::id::__init()
 {
-__id_ = __sync_add_and_fetch(&__next_id, 1);
+__id_ = __libcpp_sync_add_and_fetch(&__next_id, 1);
 }
 
 // template <> class collate_byname

Modified: libcxx/trunk/src/support/runtime/exception_fallback.ipp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_fallback.ipp?rev=307595&r1=307594&r2=307595&view=diff
==
--- libcxx/trunk/src/support/runtime/exception_fallback.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_fallback.ipp Mon Jul 10 14:37:35 
2017
@@ -9,6 +9,7 @@
 
//===--===//
 
 #include 
+#include <__atomic_support>
 
 namespace std {
 
@@ -20,13 +21,13 @@ _LIBCPP_SAFE_STATIC static std::unexpect
 unex

r302274 - [ARM] Limit the diagnose when an ISR calls a regular function

2017-05-05 Thread Weiming Zhao via cfe-commits
Author: weimingz
Date: Fri May  5 14:25:29 2017
New Revision: 302274

URL: http://llvm.org/viewvc/llvm-project?rev=302274&view=rev
Log:
[ARM] Limit the diagnose when an ISR calls a regular function

Summary:
When the function is compiled with soft-float or on CPU with no FPU, we
don't need to diagnose for a call from an ISR to a regular function.

Reviewers: jroelofs, eli.friedman

Reviewed By: jroelofs

Subscribers: aemerson, rengolin, javed.absar, cfe-commits

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

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/arm-interrupt-attr.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=302274&r1=302273&r2=302274&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri May  5 14:25:29 2017
@@ -5443,6 +5443,7 @@ public:
 .Case("softfloat", SoftFloat)
 .Case("thumb", isThumb())
 .Case("neon", (FPU & NeonFPU) && !SoftFloat)
+.Case("vfp", FPU && !SoftFloat)
 .Case("hwdiv", HWDiv & HWDivThumb)
 .Case("hwdiv-arm", HWDiv & HWDivARM)
 .Default(false);

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=302274&r1=302273&r2=302274&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri May  5 14:25:29 2017
@@ -5399,9 +5399,11 @@ Sema::BuildResolvedCallExpr(Expr *Fn, Na
   // that the callee might not preserve them. This is easy to diagnose here,
   // but can be very challenging to debug.
   if (auto *Caller = getCurFunctionDecl())
-if (Caller->hasAttr())
-  if (!FDecl || !FDecl->hasAttr())
+if (Caller->hasAttr()) {
+  bool VFP = Context.getTargetInfo().hasFeature("vfp");
+  if (VFP && (!FDecl || !FDecl->hasAttr()))
 Diag(Fn->getExprLoc(), diag::warn_arm_interrupt_calling_convention);
+}
 
   // Promote the function operand.
   // We special-case function promotion here because we only allow promoting

Modified: cfe/trunk/test/Sema/arm-interrupt-attr.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/arm-interrupt-attr.c?rev=302274&r1=302273&r2=302274&view=diff
==
--- cfe/trunk/test/Sema/arm-interrupt-attr.c (original)
+++ cfe/trunk/test/Sema/arm-interrupt-attr.c Fri May  5 14:25:29 2017
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 %s -triple arm-apple-darwin -verify -fsyntax-only
-// RUN: %clang_cc1 %s -triple thumb-apple-darwin -verify -fsyntax-only
-// RUN: %clang_cc1 %s -triple armeb-none-eabi -verify -fsyntax-only
-// RUN: %clang_cc1 %s -triple thumbeb-none-eabi -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple arm-apple-darwin  -target-feature +vfp2 -verify 
-fsyntax-only
+// RUN: %clang_cc1 %s -triple thumb-apple-darwin  -target-feature +vfp3 
-verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple armeb-none-eabi  -target-feature +vfp4 -verify 
-fsyntax-only
+// RUN: %clang_cc1 %s -triple thumbeb-none-eabi  -target-feature +neon -verify 
-fsyntax-only
+// RUN: %clang_cc1 %s -triple thumbeb-none-eabi -target-feature +neon 
-target-feature +soft-float -DSOFT -verify -fsyntax-only
 
 __attribute__((interrupt(IRQ))) void foo() {} // expected-error {{'interrupt' 
attribute requires a string}}
 __attribute__((interrupt("irq"))) void foo1() {} // expected-warning 
{{'interrupt' attribute argument not supported: irq}}
@@ -24,6 +25,8 @@ void caller1() {
   callee1();
   callee2();
 }
+
+#ifndef SOFT
 __attribute__((interrupt("IRQ"))) void caller2() {
   callee1(); // expected-warning {{call to function without interrupt 
attribute could clobber interruptee's VFP registers}}
   callee2();
@@ -33,3 +36,14 @@ void (*callee3)();
 __attribute__((interrupt("IRQ"))) void caller3() {
   callee3(); // expected-warning {{call to function without interrupt 
attribute could clobber interruptee's VFP registers}}
 }
+#else
+__attribute__((interrupt("IRQ"))) void caller2() {
+  callee1();
+  callee2();
+}
+
+void (*callee3)();
+__attribute__((interrupt("IRQ"))) void caller3() {
+  callee3();
+}
+#endif


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


Re: [PATCH] D22292: [libunwind] Fix unw_getcontext for ARMv6-m

2016-07-18 Thread Weiming Zhao via cfe-commits
weimingz added inline comments.


Comment at: src/UnwindRegistersRestore.S:325
@@ -324,4 +324,3 @@
 
DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind13Registers_arm20restoreCoreAndJumpToEv)
-#if !defined(__ARM_ARCH_ISA_ARM)
-  ldr r2, [r0, #52]
-  ldr r3, [r0, #60]
+#if !defined(__ARM_ARCH_ISA_ARM) && __ARM_ARCH_ISA_THUMB == 1
+  @ r8-r12: ldr into r1-r5, then mov to r8-r12

originally, r8-r12 were not restored. Was that some existing bug?


Comment at: src/UnwindRegistersRestore.S:326
@@ +325,3 @@
+#if !defined(__ARM_ARCH_ISA_ARM) && __ARM_ARCH_ISA_THUMB == 1
+  @ r8-r12: ldr into r1-r5, then mov to r8-r12
+  ldr r1, [r0, #0x20]

originally, r0-r7 get loaded from [r0]
now, r8-r12 get loaded from [r0+0x20]

is that expected? 



https://reviews.llvm.org/D22292



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


Re: [PATCH] D22292: [libunwind] Fix unw_getcontext for ARMv6-m

2016-07-18 Thread Weiming Zhao via cfe-commits
weimingz added inline comments.


Comment at: src/UnwindRegistersRestore.S:326
@@ +325,3 @@
+#if !defined(__ARM_ARCH_ISA_ARM) && __ARM_ARCH_ISA_THUMB == 1
+  @ r8-r12: ldr into r1-r5, then mov to r8-r12
+  ldr r1, [r0, #0x20]

weimingz wrote:
> originally, r0-r7 get loaded from [r0]
> now, r8-r12 get loaded from [r0+0x20]
> 
> is that expected? 
> 
Please ignore the comment on line 326. I thought the “x" icon will delete it.


https://reviews.llvm.org/D22292



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


Re: [PATCH] D22292: [libunwind] Fix unw_getcontext for ARMv6-m

2016-07-22 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

LGTM. 
Maybe @renato can review it too.
Thanks Oliver and Saleem.


https://reviews.llvm.org/D22292



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


Re: [PATCH] D17085: Test commit, fixed "clang" to "Clang" in docs

2016-02-10 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

LGTM


http://reviews.llvm.org/D17085



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


Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-04-08 Thread Weiming Zhao via cfe-commits
weimingz added a subscriber: weimingz.
weimingz added a comment.

Sounds good. Will do.

Thanks for reviewing


http://reviews.llvm.org/D17741



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


Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-04-08 Thread Weiming Zhao via cfe-commits
weimingz updated this revision to Diff 53105.
weimingz added a comment.

per Alex's suggestion, split into 2 flags:
-ffile-macro-prefix-to-remove=xxx : remove matched prefix
-ffile-macro-basename-only  : remove the whole dir part


http://reviews.llvm.org/D17741

Files:
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp

Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -12,7 +12,6 @@
 //
 //===--===//
 
-#include "clang/Lex/Preprocessor.h"
 #include "clang/Basic/Attributes.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
@@ -22,12 +21,15 @@
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -1595,7 +1597,7 @@
 PLoc = SourceMgr.getPresumedLoc(NextLoc);
 if (PLoc.isInvalid())
   break;
-
+
 NextLoc = PLoc.getIncludeLoc();
   }
 }
@@ -1603,7 +1605,18 @@
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
 SmallString<128> FN;
 if (PLoc.isValid()) {
-  FN += PLoc.getFilename();
+  StringRef Filename(PLoc.getFilename());
+  if (II == Ident__FILE__) {
+const std::string &PrefixToRemove =
+getPreprocessorOpts().__FILE__PrefixToRemove;
+if (getPreprocessorOpts().__FILE__BasenameOnly)
+  FN += llvm::sys::path::filename(Filename);
+else if (!PrefixToRemove.empty() && Filename.startswith(PrefixToRemove))
+  FN += Filename.substr(PrefixToRemove.size());
+else
+  FN += Filename;
+  } else
+FN += Filename;
   Lexer::Stringify(FN);
   OS << '"' << FN << '"';
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2010,6 +2010,14 @@
 else
   Opts.ObjCXXARCStandardLibrary = (ObjCXXARCStandardLibraryKind)Library;
   }
+
+  if (Arg *A =
+  Args.getLastArg(OPT_FILE_prefix_to_remove, OPT_FILE_basename_only)) {
+if (A->getOption().matches(options::OPT_FILE_basename_only))
+  Opts.__FILE__BasenameOnly = true;
+else
+  Opts.__FILE__PrefixToRemove = A->getValue();
+  }
 }
 
 static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -570,6 +570,16 @@
   // Add CUDA include arguments, if needed.
   if (types::isCuda(Inputs[0].getType()))
 getToolChain().AddCudaIncludeArgs(Args, CmdArgs);
+
+  // Add FILE macro prefix removing arguments or basename only flags.
+  if (const Arg *A = Args.getLastArg(options::OPT_FILE_prefix_to_remove,
+ options::OPT_FILE_basename_only)) {
+if (A->getOption().matches(options::OPT_FILE_basename_only))
+  CmdArgs.push_back(Args.MakeArgString("-ffile-macro-basename-only"));
+else if (!StringRef(A->getValue()).empty())
+  CmdArgs.push_back(Args.MakeArgString(
+  Twine("-ffile-macro-prefix-to-remove=") + A->getValue()));
+  }
 }
 
 // FIXME: Move to target hook.
Index: include/clang/Lex/PreprocessorOptions.h
===
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -108,15 +108,23 @@
   /// the buffers associated with remapped files.
   ///
   /// This flag defaults to false; it can be set true only through direct
-  /// manipulation of the compiler invocation object, in cases where the 
+  /// manipulation of the compiler invocation object, in cases where the
   /// compiler invocation and its buffers will be reused.
   bool RetainRemappedFileBuffers;
-  
+
   /// \brief The Objective-C++ ARC standard library that we should support,
   /// by providing appropriate definitions to retrofit the standard library
   /// with support for lifetime-qualified pointers.
   ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary;
-
+
+  /// \brief This string will be used in expanding __FILE__ macro. If it
+  /// matches the prefix of __FILE__, the matched part won't be expanded.
+  std::string __FILE__PrefixToRemove;
+
+  /// \brief This falgs defaults to false; If it is set to true

[PATCH] D19225: [ARM] predefines __ELF__ macro for arm-none-eabi

2016-04-18 Thread Weiming Zhao via cfe-commits
weimingz created this revision.
weimingz added reviewers: rengolin, silviu.baranga.
weimingz added a subscriber: cfe-commits.
Herald added subscribers: rengolin, aemerson.

redefines __ELF__ macro for arm-none-eabi

http://reviews.llvm.org/D19225

Files:
  lib/Basic/Targets.cpp
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -2162,6 +2162,9 @@
 // ARM-NETBSD:#define __arm 1
 // ARM-NETBSD:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=arm-none-eabi < /dev/null | 
FileCheck -match-full-lines -check-prefix ARM-NONE-EABI %s
+// ARM-NONE-EABI: #define __ELF__ 1
+
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7s -x c -E -dM %s -o - 
| FileCheck -match-full-lines --check-prefix=ARM-DARWIN-NO-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv6m -x c -E -dM %s -o - 
| FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7m -x c -E -dM %s -o - 
| FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -4817,6 +4817,10 @@
 // Target identification.
 Builder.defineMacro("__arm");
 Builder.defineMacro("__arm__");
+// For bare-metal none-eabi.
+if (getTriple().getOS() == llvm::Triple::UnknownOS &&
+getTriple().getEnvironment() == llvm::Triple::EABI)
+  Builder.defineMacro("__ELF__");
 
 // Target properties.
 Builder.defineMacro("__REGISTER_PREFIX__", "");


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -2162,6 +2162,9 @@
 // ARM-NETBSD:#define __arm 1
 // ARM-NETBSD:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=arm-none-eabi < /dev/null | FileCheck -match-full-lines -check-prefix ARM-NONE-EABI %s
+// ARM-NONE-EABI: #define __ELF__ 1
+
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7s -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARM-DARWIN-NO-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv6m -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7m -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -4817,6 +4817,10 @@
 // Target identification.
 Builder.defineMacro("__arm");
 Builder.defineMacro("__arm__");
+// For bare-metal none-eabi.
+if (getTriple().getOS() == llvm::Triple::UnknownOS &&
+getTriple().getEnvironment() == llvm::Triple::EABI)
+  Builder.defineMacro("__ELF__");
 
 // Target properties.
 Builder.defineMacro("__REGISTER_PREFIX__", "");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r266625 - [ARM] predefines __ELF__ macro for arm-none-eabi

2016-04-18 Thread Weiming Zhao via cfe-commits
Author: weimingz
Date: Mon Apr 18 11:25:46 2016
New Revision: 266625

URL: http://llvm.org/viewvc/llvm-project?rev=266625&view=rev
Log:
[ARM] predefines __ELF__ macro for arm-none-eabi

Summary: predefines __ELF__ macro for arm-none-eabi

Reviewers: silviu.baranga, rengolin

Subscribers: aemerson, rengolin, cfe-commits

Differential Revision: http://reviews.llvm.org/D19225

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=266625&r1=266624&r2=266625&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Mon Apr 18 11:25:46 2016
@@ -4847,6 +4847,10 @@ public:
 // Target identification.
 Builder.defineMacro("__arm");
 Builder.defineMacro("__arm__");
+// For bare-metal none-eabi.
+if (getTriple().getOS() == llvm::Triple::UnknownOS &&
+getTriple().getEnvironment() == llvm::Triple::EABI)
+  Builder.defineMacro("__ELF__");
 
 // Target properties.
 Builder.defineMacro("__REGISTER_PREFIX__", "");

Modified: cfe/trunk/test/Preprocessor/init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=266625&r1=266624&r2=266625&view=diff
==
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Mon Apr 18 11:25:46 2016
@@ -2162,6 +2162,9 @@
 // ARM-NETBSD:#define __arm 1
 // ARM-NETBSD:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=arm-none-eabi < /dev/null | 
FileCheck -match-full-lines -check-prefix ARM-NONE-EABI %s
+// ARM-NONE-EABI: #define __ELF__ 1
+
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7s -x c -E -dM %s -o - 
| FileCheck -match-full-lines --check-prefix=ARM-DARWIN-NO-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv6m -x c -E -dM %s -o - 
| FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7m -x c -E -dM %s -o - 
| FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s


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


Re: [PATCH] D19225: [ARM] predefines __ELF__ macro for arm-none-eabi

2016-04-18 Thread Weiming Zhao via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266625: [ARM] predefines __ELF__ macro for arm-none-eabi 
(authored by weimingz).

Changed prior to commit:
  http://reviews.llvm.org/D19225?vs=54070&id=54074#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19225

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/Preprocessor/init.c

Index: cfe/trunk/test/Preprocessor/init.c
===
--- cfe/trunk/test/Preprocessor/init.c
+++ cfe/trunk/test/Preprocessor/init.c
@@ -2162,6 +2162,9 @@
 // ARM-NETBSD:#define __arm 1
 // ARM-NETBSD:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=arm-none-eabi < /dev/null | 
FileCheck -match-full-lines -check-prefix ARM-NONE-EABI %s
+// ARM-NONE-EABI: #define __ELF__ 1
+
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7s -x c -E -dM %s -o - 
| FileCheck -match-full-lines --check-prefix=ARM-DARWIN-NO-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv6m -x c -E -dM %s -o - 
| FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7m -x c -E -dM %s -o - 
| FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -4847,6 +4847,10 @@
 // Target identification.
 Builder.defineMacro("__arm");
 Builder.defineMacro("__arm__");
+// For bare-metal none-eabi.
+if (getTriple().getOS() == llvm::Triple::UnknownOS &&
+getTriple().getEnvironment() == llvm::Triple::EABI)
+  Builder.defineMacro("__ELF__");
 
 // Target properties.
 Builder.defineMacro("__REGISTER_PREFIX__", "");


Index: cfe/trunk/test/Preprocessor/init.c
===
--- cfe/trunk/test/Preprocessor/init.c
+++ cfe/trunk/test/Preprocessor/init.c
@@ -2162,6 +2162,9 @@
 // ARM-NETBSD:#define __arm 1
 // ARM-NETBSD:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=arm-none-eabi < /dev/null | FileCheck -match-full-lines -check-prefix ARM-NONE-EABI %s
+// ARM-NONE-EABI: #define __ELF__ 1
+
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7s -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARM-DARWIN-NO-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv6m -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s
 // RUN: %clang -target arm-apple-darwin-eabi -arch armv7m -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARM-DARWIN-EABI %s
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -4847,6 +4847,10 @@
 // Target identification.
 Builder.defineMacro("__arm");
 Builder.defineMacro("__arm__");
+// For bare-metal none-eabi.
+if (getTriple().getOS() == llvm::Triple::UnknownOS &&
+getTriple().getEnvironment() == llvm::Triple::EABI)
+  Builder.defineMacro("__ELF__");
 
 // Target properties.
 Builder.defineMacro("__REGISTER_PREFIX__", "");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19344: [libc++] fix constexpr error when build with MUSL and macro redef warning when no exception

2016-04-20 Thread Weiming Zhao via cfe-commits
weimingz added inline comments.


Comment at: include/__config:300
@@ -299,3 +299,3 @@
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS

Is this change OK?


Comment at: include/__mutex_base:43
@@ -42,3 +42,3 @@
 _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR
  constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}

EricWF wrote:
> This is not OK. It's critical that mutex have a constexpr constructor that it 
> runs during the "Constant initialization" phase of static initialization.
> Heres an example of the difference this makes: https://godbolt.org/g/3cvlMJ
> 
> Also the constructor is specified as being constexpr in C++11. We can't turn 
> that off. 
> 
> If one particular pthread implementation is broken then we need a fix 
> targeted to only that implementation.  However this seems like a pthread bug 
> and not a libc++ bug.
The macro has an "#else" part.  I'm not familiar with this, but it seems the 
constexpr an "optional feature".





http://reviews.llvm.org/D19344



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


Re: [PATCH] D19344: [libc++] fix macro redef warning when exception is disabled

2016-04-20 Thread Weiming Zhao via cfe-commits
weimingz retitled this revision from "[libc++] fix constexpr error when build 
with MUSL and macro redef warning when no exception" to "[libc++] fix macro 
redef warning when exception is disabled".
weimingz updated the summary for this revision.
weimingz updated this revision to Diff 54457.

http://reviews.llvm.org/D19344

Files:
  include/__config

Index: include/__config
===
--- include/__config
+++ include/__config
@@ -297,7 +297,7 @@
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 


Index: include/__config
===
--- include/__config
+++ include/__config
@@ -297,7 +297,7 @@
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19344: [libc++] fix macro redef warning when exception is disabled

2016-04-20 Thread Weiming Zhao via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266956: [libc++] fix macro redef warning when exception is 
disabled (authored by weimingz).

Changed prior to commit:
  http://reviews.llvm.org/D19344?vs=54457&id=54459#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19344

Files:
  libcxx/trunk/include/__config

Index: libcxx/trunk/include/__config
===
--- libcxx/trunk/include/__config
+++ libcxx/trunk/include/__config
@@ -297,7 +297,7 @@
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 


Index: libcxx/trunk/include/__config
===
--- libcxx/trunk/include/__config
+++ libcxx/trunk/include/__config
@@ -297,7 +297,7 @@
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r266956 - [libc++] fix macro redef warning when exception is disabled

2016-04-20 Thread Weiming Zhao via cfe-commits
Author: weimingz
Date: Thu Apr 21 00:28:18 2016
New Revision: 266956

URL: http://llvm.org/viewvc/llvm-project?rev=266956&view=rev
Log:
[libc++] fix macro redef warning when exception is disabled

Summary:
 when setting LIBCXX_ENABLE_EXCEPTIONS=false, _LIBCPP_NO_EXCEPTIONS wil be 
defined in both commandline and _config

Reviewers: bcraig, EricWF

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19344

Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=266956&r1=266955&r2=266956&view=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Thu Apr 21 00:28:18 2016
@@ -297,7 +297,7 @@ typedef __char16_t char16_t;
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 


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


Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-04-22 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

Ping ?


http://reviews.llvm.org/D17741



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


[PATCH] D21673: [libcxx] guard throw with exception enabling check

2016-06-23 Thread Weiming Zhao via cfe-commits
weimingz created this revision.
weimingz added a subscriber: cfe-commits.

this fixes build error when built with c++14 and no exceptions

http://reviews.llvm.org/D21673

Files:
  include/experimental/optional

Index: include/experimental/optional
===
--- include/experimental/optional
+++ include/experimental/optional
@@ -517,7 +517,11 @@
 constexpr value_type const& value() const
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 
@@ -525,7 +529,11 @@
 value_type& value()
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 


Index: include/experimental/optional
===
--- include/experimental/optional
+++ include/experimental/optional
@@ -517,7 +517,11 @@
 constexpr value_type const& value() const
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 
@@ -525,7 +529,11 @@
 value_type& value()
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21673: [libcxx] guard throw with exception enabling check

2016-06-24 Thread Weiming Zhao via cfe-commits
weimingz added a subscriber: weimingz.
weimingz added a comment.

It's a good idea. Currently, there are about 600+  "throws" being 
guarded by _LIBCPP_NO_EXCEPTIONS macro.

How about let's merge the patch now and I can do the conversion of 
existing code to the wrapper in background?

Weiming


http://reviews.llvm.org/D21673



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


Re: [PATCH] D21673: [libcxx] guard throw with exception enabling check

2016-06-24 Thread Weiming Zhao via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL273697: [libcxx] guard throw with exception enabling check 
(authored by weimingz).

Changed prior to commit:
  http://reviews.llvm.org/D21673?vs=61755&id=61813#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D21673

Files:
  libcxx/trunk/include/experimental/optional

Index: libcxx/trunk/include/experimental/optional
===
--- libcxx/trunk/include/experimental/optional
+++ libcxx/trunk/include/experimental/optional
@@ -517,15 +517,23 @@
 constexpr value_type const& value() const
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 
 _LIBCPP_INLINE_VISIBILITY
 value_type& value()
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 


Index: libcxx/trunk/include/experimental/optional
===
--- libcxx/trunk/include/experimental/optional
+++ libcxx/trunk/include/experimental/optional
@@ -517,15 +517,23 @@
 constexpr value_type const& value() const
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 
 _LIBCPP_INLINE_VISIBILITY
 value_type& value()
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r273697 - [libcxx] guard throw with exception enabling check

2016-06-24 Thread Weiming Zhao via cfe-commits
Author: weimingz
Date: Fri Jun 24 13:02:27 2016
New Revision: 273697

URL: http://llvm.org/viewvc/llvm-project?rev=273697&view=rev
Log:
[libcxx] guard throw with exception enabling check

Summary: this fixes build error when built with c++14 and no exceptions

Reviewers: rmaprath

Subscribers: weimingz, grandinj, rmaprath, cfe-commits

Differential Revision: http://reviews.llvm.org/D21673

Modified:
libcxx/trunk/include/experimental/optional

Modified: libcxx/trunk/include/experimental/optional
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/optional?rev=273697&r1=273696&r2=273697&view=diff
==
--- libcxx/trunk/include/experimental/optional (original)
+++ libcxx/trunk/include/experimental/optional Fri Jun 24 13:02:27 2016
@@ -517,7 +517,11 @@ public:
 constexpr value_type const& value() const
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 
@@ -525,7 +529,11 @@ public:
 value_type& value()
 {
 if (!this->__engaged_)
+#ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_optional_access();
+#else
+assert(!"bad optional access");
+#endif
 return this->__val_;
 }
 


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


[PATCH] D21706: [libcxx] refactor for throw or assert

2016-06-24 Thread Weiming Zhao via cfe-commits
weimingz created this revision.
weimingz added reviewers: rmaprath, grandinj.
weimingz added a subscriber: cfe-commits.

Add macros to wrapper for throw or assert.

http://reviews.llvm.org/D21706

Files:
  include/__config
  include/__locale
  include/array
  include/experimental/optional
  include/fstream

Index: include/fstream
===
--- include/fstream
+++ include/fstream
@@ -618,10 +618,8 @@
 size_t __nr = fread((void*)__extbufnext_, 1, __nmemb, __file_);
 if (__nr != 0)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (!__cv_)
-throw bad_cast();
-#endif
+_LIBCXX_THROW_OR_ASSERT(bad_cast(), "bad cast");
 __extbufend_ = __extbufnext_ + __nr;
 char_type*  __inext;
 __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_,
Index: include/experimental/optional
===
--- include/experimental/optional
+++ include/experimental/optional
@@ -517,11 +517,7 @@
 constexpr value_type const& value() const
 {
 if (!this->__engaged_)
-#ifndef _LIBCPP_NO_EXCEPTIONS
-throw bad_optional_access();
-#else
-assert(!"bad optional access");
-#endif
+  _LIBCXX_THROW_OR_ASSERT(bad_optional_access(), "bad optional access");
 return this->__val_;
 }
 
@@ -529,11 +525,7 @@
 value_type& value()
 {
 if (!this->__engaged_)
-#ifndef _LIBCPP_NO_EXCEPTIONS
-throw bad_optional_access();
-#else
-assert(!"bad optional access");
-#endif
+_LIBCXX_THROW_OR_ASSERT(bad_optional_access(), "bad optional access");
 return this->__val_;
 }
 
Index: include/array
===
--- include/array
+++ include/array
@@ -108,9 +108,6 @@
 #include 
 #include 
 #include 
-#if defined(_LIBCPP_NO_EXCEPTIONS)
-#include 
-#endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -209,11 +206,7 @@
 array<_Tp, _Size>::at(size_type __n)
 {
 if (__n >= _Size)
-#ifndef _LIBCPP_NO_EXCEPTIONS
-throw out_of_range("array::at");
-#else
-assert(!"array::at out_of_range");
-#endif
+_LIBCXX_THROW_OR_ASSERT(out_of_range("array::at"), "array::at out_of_range");
 return __elems_[__n];
 }
 
Index: include/__locale
===
--- include/__locale
+++ include/__locale
@@ -165,10 +165,8 @@
 locale
 locale::combine(const locale& __other) const
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (!_VSTD::has_facet<_Facet>(__other))
-throw runtime_error("locale::combine: locale missing facet");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+_LIBCXX_THROW_OR_ASSERT_RUNTIME("locale::combine: locale missing facet");
 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
 }
 
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -890,6 +890,18 @@
 #define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
 #endif
 
+#if (defined(_LIBCPP_NO_EXCEPTIONS))
+#include 
+#define _LIBCXX_THROW_OR_ASSERT(e, msg) assert(! msg) // generic wrapper.
+#define _LIBCXX_THROW_OR_ASSERT_MSG(e, msg) assert (! msg) // same msg for exception and assert.
+#define _LIBCXX_THROW_OR_ASSERT_RUNTIME(msg) assert(! msg) // wrapper for runtime error.
+#else
+#define _LIBCXX_THROW_OR_ASSERT(e, msg) throw e
+#define _LIBCXX_THROW_OR_ASSERT_MSG(e, msg) throw e(msg)
+#define _LIBCXX_THROW_OR_ASSERT_RUNTIME(msg)  _LIBCXX_THROW_OR_ASSERT_MSG(runtime_error, msg)
+
+#endif
+
 #endif // __cplusplus
 
 #endif // _LIBCPP_CONFIG
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21706: [libcxx] refactor for throw or assert

2016-06-24 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

Before replacing all throw/assert to macros, let's first check if we're on the 
right path.


http://reviews.llvm.org/D21706



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


[PATCH] D21708: [libcxx] fix compiler warning of autological-constant-out-of-range-compare

2016-06-24 Thread Weiming Zhao via cfe-commits
weimingz created this revision.
weimingz added a subscriber: cfe-commits.

warning: comparison of constant -2147483648 with expression of type 'long' 
(range [-2147483648, 2147483647]) is always false 
[-Wtautological-constant-out-of-range-compare]

As int and long maybe the same size on most architectures, the test doesn't 
really tell if the value is out of range or not.

The fix changes to "long long". But may still not the best way as there is no 
guarantee that it would be bigger than int. 


http://reviews.llvm.org/D21708

Files:
  src/string.cpp

Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -90,7 +90,7 @@
 as_integer(const string& func, const string& s, size_t* idx, int base )
 {
 // Use long as no Standard string to integer exists.
-long r = as_integer_helper( func, s, idx, base, strtol );
+long long r = as_integer_helper( func, s, idx, base, strtol );
 if (r < numeric_limits::min() || numeric_limits::max() < r)
 throw_from_string_out_of_range(func);
 return static_cast(r);
@@ -135,7 +135,7 @@
 as_integer( const string& func, const wstring& s, size_t* idx, int base )
 {
 // Use long as no Stantard string to integer exists.
-long r = as_integer_helper( func, s, idx, base, wcstol );
+long long r = as_integer_helper( func, s, idx, base, wcstol );
 if (r < numeric_limits::min() || numeric_limits::max() < r)
 throw_from_string_out_of_range(func);
 return static_cast(r);


Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -90,7 +90,7 @@
 as_integer(const string& func, const string& s, size_t* idx, int base )
 {
 // Use long as no Standard string to integer exists.
-long r = as_integer_helper( func, s, idx, base, strtol );
+long long r = as_integer_helper( func, s, idx, base, strtol );
 if (r < numeric_limits::min() || numeric_limits::max() < r)
 throw_from_string_out_of_range(func);
 return static_cast(r);
@@ -135,7 +135,7 @@
 as_integer( const string& func, const wstring& s, size_t* idx, int base )
 {
 // Use long as no Stantard string to integer exists.
-long r = as_integer_helper( func, s, idx, base, wcstol );
+long long r = as_integer_helper( func, s, idx, base, wcstol );
 if (r < numeric_limits::min() || numeric_limits::max() < r)
 throw_from_string_out_of_range(func);
 return static_cast(r);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21706: [libcxx] refactor for throw or assert

2016-06-30 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

In http://reviews.llvm.org/D21706#471091, @EricWF wrote:

> Please make the changes in the above comment.


Sure. I'm working on it. Just got interrupted/distracted by other tasks time to 
time. :(


http://reviews.llvm.org/D21706



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


Re: [PATCH] D21706: [libcxx] refactor for throw

2016-06-30 Thread Weiming Zhao via cfe-commits
weimingz retitled this revision from "[libcxx] refactor for throw or assert" to 
"[libcxx] refactor for throw".
weimingz updated the summary for this revision.
weimingz updated this revision to Diff 62470.

http://reviews.llvm.org/D21706

Files:
  include/__functional_03
  include/__locale
  include/array
  include/bitset
  include/complex
  include/deque
  include/exception
  include/experimental/dynarray
  include/experimental/optional
  include/fstream
  include/functional
  include/future
  include/locale
  include/map
  include/memory
  include/regex
  include/string
  include/unordered_map
  include/vector
  src/debug.cpp
  src/experimental/memory_resource.cpp
  src/future.cpp
  src/hash.cpp
  src/ios.cpp
  src/locale.cpp
  src/new.cpp
  src/string.cpp
  src/system_error.cpp
  src/thread.cpp
  src/typeinfo.cpp

Index: src/typeinfo.cpp
===
--- src/typeinfo.cpp
+++ src/typeinfo.cpp
@@ -52,15 +52,11 @@
   // because bad_cast and bad_typeid are defined in his higher level library
   void __cxxabiv1::__cxa_bad_typeid()
   {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw std::bad_typeid();
-#endif
+ __libcpp_throw(std::bad_typeid());
   }
   void __cxxabiv1::__cxa_bad_cast()
   {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-  throw std::bad_cast();
-#endif
+  __libcpp_throw(std::bad_cast());
   }
 #endif
 
Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -53,10 +53,9 @@
 if (ec == 0)
 __t_ = 0;
 }
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (ec)
-throw system_error(error_code(ec, system_category()), "thread::join failed");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+__libcpp_throw(system_error(error_code(ec, system_category()),
+   "thread::join failed"));
 }
 
 void
@@ -69,10 +68,9 @@
 if (ec == 0)
 __t_ = 0;
 }
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (ec)
-throw system_error(error_code(ec, system_category()), "thread::detach failed");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+__libcpp_throw(system_error(error_code(ec, system_category()),
+   "thread::detach failed"));
 }
 
 unsigned
Index: src/system_error.cpp
===
--- src/system_error.cpp
+++ src/system_error.cpp
@@ -253,12 +253,7 @@
 void
 __throw_system_error(int ev, const char* what_arg)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-throw system_error(error_code(ev, system_category()), what_arg);
-#else
-(void)ev;
-(void)what_arg;
-#endif
+__libcpp_throw(system_error(error_code(ev, system_category()), what_arg));
 }
 
 _LIBCPP_END_NAMESPACE_STD
Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -32,28 +32,16 @@
 namespace
 {
 
-template
-inline
-void throw_helper( const string& msg )
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
-throw T( msg );
-#else
-fprintf(stderr, "%s\n", msg.c_str());
-abort();
-#endif
-}
-
 inline
 void throw_from_string_out_of_range( const string& func )
 {
-throw_helper(func + ": out of range");
+__libcpp_throw(out_of_range(func + ": out of range"));
 }
 
 inline
 void throw_from_string_invalid_arg( const string& func )
 {
-throw_helper(func + ": no conversion");
+__libcpp_throw(invalid_argument(func + ": no conversion"));
 }
 
 // as_integer
Index: src/new.cpp
===
--- src/new.cpp
+++ src/new.cpp
@@ -56,7 +56,7 @@
 nh();
 else
 #ifndef _LIBCPP_NO_EXCEPTIONS
-throw std::bad_alloc();
+__libcpp_throw(std::bad_alloc());
 #else
 break;
 #endif
Index: src/locale.cpp
===
--- src/locale.cpp
+++ src/locale.cpp
@@ -436,10 +436,8 @@
 const locale::facet*
 locale::__imp::use_facet(long id) const
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (!has_facet(id))
-throw bad_cast();
-#endif  // _LIBCPP_NO_EXCEPTIONS
+__libcpp_throw(bad_cast());
 return facets_[static_cast(id)];
 }
 
@@ -528,6 +526,7 @@
 #else  // _LIBCPP_NO_EXCEPTIONS
 : __locale_(new __imp(*other.__locale_, name, c))
 #endif
+
 {
 __locale_->__add_shared();
 }
@@ -646,22 +645,18 @@
 : collate(refs),
   __l(newlocale(LC_ALL_MASK, n, 0))
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (__l == 0)
-throw runtime_error("collate_byname::collate_byname"
-" failed to construct for " + string(n));
-#endif  // _LIBCPP_NO_EXCEPTIONS
+__libcpp_throw(runtime_error("collate_byname::collate_byname"
+" failed to construct for " + string(n)));
 }
 
 collate_byname::collate_byname(const string& name, size_t refs)
 : collate(refs),
   __l(newlocale(LC_ALL_MASK, name.c

Re: [PATCH] D21706: [libcxx] refactor for throw

2016-07-01 Thread Weiming Zhao via cfe-commits
weimingz updated this revision to Diff 62515.
weimingz marked 5 inline comments as done.
weimingz added a comment.

fix issues per Noel's suggestion


http://reviews.llvm.org/D21706

Files:
  include/__functional_03
  include/__locale
  include/array
  include/bitset
  include/complex
  include/deque
  include/exception
  include/experimental/dynarray
  include/experimental/optional
  include/fstream
  include/functional
  include/future
  include/locale
  include/map
  include/memory
  include/regex
  include/string
  include/unordered_map
  include/vector
  src/debug.cpp
  src/experimental/memory_resource.cpp
  src/future.cpp
  src/hash.cpp
  src/ios.cpp
  src/locale.cpp
  src/new.cpp
  src/string.cpp
  src/system_error.cpp
  src/thread.cpp
  src/typeinfo.cpp

Index: src/typeinfo.cpp
===
--- src/typeinfo.cpp
+++ src/typeinfo.cpp
@@ -52,15 +52,11 @@
   // because bad_cast and bad_typeid are defined in his higher level library
   void __cxxabiv1::__cxa_bad_typeid()
   {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw std::bad_typeid();
-#endif
+ __libcpp_throw(std::bad_typeid());
   }
   void __cxxabiv1::__cxa_bad_cast()
   {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-  throw std::bad_cast();
-#endif
+  __libcpp_throw(std::bad_cast());
   }
 #endif
 
Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -53,10 +53,9 @@
 if (ec == 0)
 __t_ = 0;
 }
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (ec)
-throw system_error(error_code(ec, system_category()), "thread::join failed");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+__libcpp_throw(system_error(error_code(ec, system_category()),
+   "thread::join failed"));
 }
 
 void
@@ -69,10 +68,9 @@
 if (ec == 0)
 __t_ = 0;
 }
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (ec)
-throw system_error(error_code(ec, system_category()), "thread::detach failed");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+__libcpp_throw(system_error(error_code(ec, system_category()),
+   "thread::detach failed"));
 }
 
 unsigned
Index: src/system_error.cpp
===
--- src/system_error.cpp
+++ src/system_error.cpp
@@ -253,12 +253,7 @@
 void
 __throw_system_error(int ev, const char* what_arg)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-throw system_error(error_code(ev, system_category()), what_arg);
-#else
-(void)ev;
-(void)what_arg;
-#endif
+__libcpp_throw(system_error(error_code(ev, system_category()), what_arg));
 }
 
 _LIBCPP_END_NAMESPACE_STD
Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -32,28 +32,16 @@
 namespace
 {
 
-template
-inline
-void throw_helper( const string& msg )
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
-throw T( msg );
-#else
-fprintf(stderr, "%s\n", msg.c_str());
-abort();
-#endif
-}
-
 inline
 void throw_from_string_out_of_range( const string& func )
 {
-throw_helper(func + ": out of range");
+__libcpp_throw(out_of_range(func + ": out of range"));
 }
 
 inline
 void throw_from_string_invalid_arg( const string& func )
 {
-throw_helper(func + ": no conversion");
+__libcpp_throw(invalid_argument(func + ": no conversion"));
 }
 
 // as_integer
Index: src/new.cpp
===
--- src/new.cpp
+++ src/new.cpp
@@ -56,7 +56,7 @@
 nh();
 else
 #ifndef _LIBCPP_NO_EXCEPTIONS
-throw std::bad_alloc();
+__libcpp_throw(std::bad_alloc());
 #else
 break;
 #endif
Index: src/locale.cpp
===
--- src/locale.cpp
+++ src/locale.cpp
@@ -436,10 +436,8 @@
 const locale::facet*
 locale::__imp::use_facet(long id) const
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (!has_facet(id))
-throw bad_cast();
-#endif  // _LIBCPP_NO_EXCEPTIONS
+__libcpp_throw(bad_cast());
 return facets_[static_cast(id)];
 }
 
@@ -528,6 +526,7 @@
 #else  // _LIBCPP_NO_EXCEPTIONS
 : __locale_(new __imp(*other.__locale_, name, c))
 #endif
+
 {
 __locale_->__add_shared();
 }
@@ -646,22 +645,18 @@
 : collate(refs),
   __l(newlocale(LC_ALL_MASK, n, 0))
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (__l == 0)
-throw runtime_error("collate_byname::collate_byname"
-" failed to construct for " + string(n));
-#endif  // _LIBCPP_NO_EXCEPTIONS
+__libcpp_throw(runtime_error("collate_byname::collate_byname"
+" failed to construct for " + string(n)));
 }
 
 collate_byname::collate_byname(const string& name, size_t refs)
 : collate(refs),
   __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
 if (_

Re: [PATCH] D21706: [libcxx] refactor for throw

2016-07-01 Thread Weiming Zhao via cfe-commits
weimingz added inline comments.


Comment at: include/exception:262
@@ -261,3 +261,3 @@
 _LIBCPP_INLINE_VISIBILITY
-inline void __libcpp_throw(_Exception const& __e) {
+inline __attribute__((noreturn)) void __libcpp_throw(_Exception const& __e) {
 #ifndef _LIBCPP_NO_EXCEPTIONS

mclow.lists wrote:
> I thought that we were going to add a macro for the "no return if no 
> exceptions"
something like this?

#ifndef __LIBCPP_NO_EXCEPTIONS
  #define NORETURN_EXP __attribute__((noreturn))
#else
  #define NORETURN_EXP
#endif

inline NORETURN_EXP void __libcpp_throw(_Exception const& __e) {
  ...
}


Comment at: src/future.cpp:96
@@ -96,4 +95,3 @@
 if (__has_value())
-throw 
future_error(make_error_code(future_errc::promise_already_satisfied));
-#endif
+
__libcpp_throw(future_error(make_error_code(future_errc::promise_already_satisfied)));
 __state_ |= __constructed | ready;

mclow.lists wrote:
> Is the indentation right here? (or is phab lying to me?)
It looks ok here. The first underscore  is on the same column as "__has_value" 
(the line above). 4 space indention


Comment at: src/locale.cpp:527
@@ -528,3 +526,3 @@
 #else  // _LIBCPP_NO_EXCEPTIONS
 : __locale_(new __imp(*other.__locale_, name, c))
 #endif

mclow.lists wrote:
> Did you miss one here?
The reason I skipeed this and two or three other similar cases is the 
constructor expects the function __libcpp_throw() to return a pointer. 


http://reviews.llvm.org/D21706



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


Re: [PATCH] D21706: [libcxx] refactor for throw

2016-07-11 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

Hi Marshall, do you have any comments?


http://reviews.llvm.org/D21706



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


[PATCH] D22292: [libunwind] Fix unw_getcontext for ARMv6-m

2016-07-12 Thread Weiming Zhao via cfe-commits
weimingz created this revision.
weimingz added reviewers: rengolin, rmaprath.
weimingz added a subscriber: cfe-commits.
Herald added subscribers: rengolin, aemerson.

ARMv6-m requires the writeback suffix for stm. 

http://reviews.llvm.org/D22292

Files:
  src/UnwindRegistersSave.S

Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -310,7 +310,8 @@
   .p2align 2
 DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
 #if !defined(__ARM_ARCH_ISA_ARM)
-  stm r0, {r0-r7}
+  stm r0!, {r0-r7}
+  subs r0, r0, #32
   mov r2, sp
   mov r3, lr
   str r2, [r0, #52]


Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -310,7 +310,8 @@
   .p2align 2
 DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
 #if !defined(__ARM_ARCH_ISA_ARM)
-  stm r0, {r0-r7}
+  stm r0!, {r0-r7}
+  subs r0, r0, #32
   mov r2, sp
   mov r3, lr
   str r2, [r0, #52]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22292: [libunwind] Fix unw_getcontext for ARMv6-m

2016-07-13 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

In http://reviews.llvm.org/D22292#482750, @rmaprath wrote:

> In http://reviews.llvm.org/D22292#482560, @compnerd wrote:
>
> > Can you explain why the write back is needed?  You are doing the write back 
> > on r0, but then adjusting it back.  So it is unclear why this change is 
> > needed.  Could you provide some more context.  A test case would be even 
> > better.
>
>
> This is because `STM` without write-back is only defined in Thumb-2 (Thumb-1 
> version must always have write-back set).
>
> Now, I scanned through our downstream sources and realized we have some local 
> patches in this area that addresses this (in a bit more general way - and 
> possibly some other fixes).
>
> @weimingz: If you can hold off for a bit, I can put these patches for review 
> and sort these out for good (need to clean up the patches first). If you want 
> to get this fixed asap, you should add a check for `__ARM_ARCH_ISA_THUMB == 
> 1` in addition to `!defined(__ARM_ARCH_ISA_ARM)`.


Cool. We can hold off. Please upload the patches.


http://reviews.llvm.org/D22292



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


[PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-02-29 Thread Weiming Zhao via cfe-commits
weimingz created this revision.
weimingz added a subscriber: cfe-commits.

__FILE__ will be expanded to the full path. In some embedded system scenarios, 
the final images is linked from many objs and the image size is a very 
important factor.
The full filenames can occupy a lot space in the string pool and most of the 
time,  knowing the base name is sufficient.
__FILE_BASENAME__ can be used in this scenario.

http://reviews.llvm.org/D17741

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/PPMacroExpansion.cpp
  test/Lexer/file_basename.c

Index: test/Lexer/file_basename.c
===
--- /dev/null
+++ test/Lexer/file_basename.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -E %s | FileCheck %s
+
+const char *filename (const char *name) {
+  // CHECK:  static const char this_file_basename[] = "file_basename.c";
+  static const char this_file_basename[] = __FILE_BASENAME__;
+  // CHECK:  static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  static const char this_file[] = __FILE__;
+  return this_file;
+}
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -28,6 +28,7 @@
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -292,6 +293,7 @@
 void Preprocessor::RegisterBuiltinMacros() {
   Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
   Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");
+  Ident__FILE_BASENAME__ = RegisterBuiltinMacro(*this, "__FILE_BASENAME__");
   Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");
   Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
   Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
@@ -1509,7 +1511,8 @@
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(tok::numeric_constant);
-  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
+  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
+ II == Ident__FILE_BASENAME__) {
 // C99 6.10.8: "__FILE__: The presumed name of the current source file (a
 // character string literal)". This can be affected by #line.
 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
@@ -1530,7 +1533,9 @@
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
 SmallString<128> FN;
 if (PLoc.isValid()) {
-  FN += PLoc.getFilename();
+  FN += II == Ident__FILE_BASENAME__
+  ? llvm::sys::path::filename(PLoc.getFilename())
+  : PLoc.getFilename();
   Lexer::Stringify(FN);
   OS << '"' << FN << '"';
 }
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -119,6 +119,7 @@
 
   /// Identifiers for builtin macros and other builtins.
   IdentifierInfo *Ident__LINE__, *Ident__FILE__;   // __LINE__, __FILE__
+  IdentifierInfo *Ident__FILE_BASENAME__;  //  __FILE_BASENAME__
   IdentifierInfo *Ident__DATE__, *Ident__TIME__;   // __DATE__, __TIME__
   IdentifierInfo *Ident__INCLUDE_LEVEL__;  // __INCLUDE_LEVEL__
   IdentifierInfo *Ident__BASE_FILE__;  // __BASE_FILE__


Index: test/Lexer/file_basename.c
===
--- /dev/null
+++ test/Lexer/file_basename.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -E %s | FileCheck %s
+
+const char *filename (const char *name) {
+  // CHECK:  static const char this_file_basename[] = "file_basename.c";
+  static const char this_file_basename[] = __FILE_BASENAME__;
+  // CHECK:  static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  static const char this_file[] = __FILE__;
+  return this_file;
+}
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -28,6 +28,7 @@
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -292,6 +293,7 @@
 void Preprocessor::RegisterBuiltinMacros() {
   Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
   Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");
+  Ident__FILE_BASENAME__ = RegisterBuiltinMacro(*this, "__FILE_BASENAME__");
   Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");
   Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
   Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
@@ -1509,7 +1511,8 @@
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(to

Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-02-29 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

In http://reviews.llvm.org/D17741#364742, @bcraig wrote:

> Note: this doesn't count as an official "LGTM".
>
> The code change seems fine to me.  I think this has been implemented in gcc 
> as well, but I don't recall for certain.  If this has been implemented in 
> gcc, then I would expect the semantics to be the same.  If it hasn't been 
> implemented in gcc, then we might want to pick a different name for the macro 
> (e.g. __CLANG_FILE_BASENAME__).


GCC has a macro "__BASE_FILE__", which I initially thought was for this 
purpose, but it's not.
__BASE_FILE__

  This macro expands to the name of the main input file, in the form of a C 
string constant. This is the source file that was specified on the command line 
of the preprocessor or C compiler. 

I will rename the macro to CLANG_FILE_BASENAME


http://reviews.llvm.org/D17741



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


Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-02-29 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

In http://reviews.llvm.org/D17741#364756, @thakis wrote:

> Instead of doing this, would it make sense to have a flag like 
> -ffile-basename that changes what __FILE__ expands to?
>
> I had wished I'd be able to have some control over __FILE__ (I'd like to say 
> "make all __FILE__s relative to this given directory for my use case), and 
> changing __FILE__ to something else in all the world's code isn't easy – so 
> maybe having a flag that provides some control over __FILE__ instead of 
> adding a separate macro would be a good idea.


do you mean this?
if source file is /a/b/c/d/foo.c and if  -ffile-name-stem-remove=/a/b/c, then 
_FILE_ will be expanded to "d/foo.c" ?


http://reviews.llvm.org/D17741



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


Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-02-29 Thread Weiming Zhao via cfe-commits
weimingz updated this revision to Diff 49445.
weimingz added a comment.

rename the macro to CLANG_FILE_BASENAME per Ben's comments.


http://reviews.llvm.org/D17741

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/PPMacroExpansion.cpp
  test/Lexer/file_basename.c

Index: test/Lexer/file_basename.c
===
--- /dev/null
+++ test/Lexer/file_basename.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -E %s | FileCheck %s
+
+const char *filename (const char *name) {
+  // CHECK:  static const char this_file_basename[] = "file_basename.c";
+  static const char this_file_basename[] = __CLANG_FILE_BASENAME__;
+  // CHECK:  static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  static const char this_file[] = __FILE__;
+  return this_file;
+}
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -28,6 +28,7 @@
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -292,6 +293,8 @@
 void Preprocessor::RegisterBuiltinMacros() {
   Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
   Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");
+  Ident__CLANG_FILE_BASENAME__ =
+  RegisterBuiltinMacro(*this, "__CLANG_FILE_BASENAME__");
   Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");
   Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
   Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
@@ -1509,7 +1512,8 @@
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(tok::numeric_constant);
-  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
+  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
+ II == Ident__CLANG_FILE_BASENAME__) {
 // C99 6.10.8: "__FILE__: The presumed name of the current source file (a
 // character string literal)". This can be affected by #line.
 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
@@ -1530,7 +1534,9 @@
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
 SmallString<128> FN;
 if (PLoc.isValid()) {
-  FN += PLoc.getFilename();
+  FN += II == Ident__CLANG_FILE_BASENAME__
+? llvm::sys::path::filename(PLoc.getFilename())
+: PLoc.getFilename();
   Lexer::Stringify(FN);
   OS << '"' << FN << '"';
 }
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -119,6 +119,7 @@
 
   /// Identifiers for builtin macros and other builtins.
   IdentifierInfo *Ident__LINE__, *Ident__FILE__;   // __LINE__, __FILE__
+  IdentifierInfo *Ident__CLANG_FILE_BASENAME__;//  __FILE_BASENAME__
   IdentifierInfo *Ident__DATE__, *Ident__TIME__;   // __DATE__, __TIME__
   IdentifierInfo *Ident__INCLUDE_LEVEL__;  // __INCLUDE_LEVEL__
   IdentifierInfo *Ident__BASE_FILE__;  // __BASE_FILE__


Index: test/Lexer/file_basename.c
===
--- /dev/null
+++ test/Lexer/file_basename.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -E %s | FileCheck %s
+
+const char *filename (const char *name) {
+  // CHECK:  static const char this_file_basename[] = "file_basename.c";
+  static const char this_file_basename[] = __CLANG_FILE_BASENAME__;
+  // CHECK:  static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  static const char this_file[] = __FILE__;
+  return this_file;
+}
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -28,6 +28,7 @@
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -292,6 +293,8 @@
 void Preprocessor::RegisterBuiltinMacros() {
   Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
   Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");
+  Ident__CLANG_FILE_BASENAME__ =
+  RegisterBuiltinMacro(*this, "__CLANG_FILE_BASENAME__");
   Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");
   Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
   Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
@@ -1509,7 +1512,8 @@
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(tok::numeric_constant);
-  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
+  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
+ II == Ident__CLANG_FILE_BASENAME__) {
   

Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-03-01 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

In http://reviews.llvm.org/D17741#364954, @thakis wrote:

> In http://reviews.llvm.org/D17741#364931, @weimingz wrote:
>
> > In http://reviews.llvm.org/D17741#364756, @thakis wrote:
> >
> > > Instead of doing this, would it make sense to have a flag like 
> > > -ffile-basename that changes what __FILE__ expands to?
> > >
> > > I had wished I'd be able to have some control over __FILE__ (I'd like to 
> > > say "make all __FILE__s relative to this given directory for my use 
> > > case), and changing __FILE__ to something else in all the world's code 
> > > isn't easy – so maybe having a flag that provides some control over 
> > > __FILE__ instead of adding a separate macro would be a good idea.
> >
> >
> > do you mean this?
> >  if source file is /a/b/c/d/foo.c and if  -ffile-name-stem-remove=/a/b/c, 
> > then _FILE_ will be expanded to "d/foo.c" ?
>
>
> Yes, something like that. Maybe it could look like 
> `-f__file__-expansion=basename` (to make __FILE__ expand to just the 
> basename, what you want), `-f__file__-expansion=relative-to:/a/b/c` to make 
> it relative to a given path.


I think we can do this separately. A "basename" macro is easier for programmers 
to use and no build system change needed.


http://reviews.llvm.org/D17741



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


Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-03-03 Thread Weiming Zhao via cfe-commits
weimingz updated this revision to Diff 49713.
weimingz added a comment.

Add "-f__FILE__-prefix-to-remove" flag to support the trim of the prefix.
Passing special value __ALL_DIR__  to remove all dir parts.

For example FILE is /a/b/c
-f__FILE__-prefix-to-remove=/a/ will cause FILE be expanded to b/c


http://reviews.llvm.org/D17741

Files:
  include/clang/Driver/Options.td
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/Lexer/file_basename.c

Index: test/Lexer/file_basename.c
===
--- /dev/null
+++ test/Lexer/file_basename.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -E %s | FileCheck %s --check-prefix=ALL --check-prefix=DEFAULT
+
+// RUN: %clang_cc1 -E -f__FILE__-prefix-to-remove=__ALL_DIR__ %s | FileCheck %s --check-prefix=ALL --check-prefix=NO-DIR
+// RUN:%clang -E -f__FILE__-prefix-to-remove=__ALL_DIR__ %s | FileCheck %s --check-prefix=ALL --check-prefix=NO-DIR
+
+// RUN: %clang_cc1 -E -f__FILE__-prefix-to-remove=%s %s | FileCheck %s --check-prefix=ALL --check-prefix=REMOVE-ALL
+// RUN: %clang -E -f__FILE__-prefix-to-remove=%s %s | FileCheck %s --check-prefix=ALL --check-prefix=REMOVE-ALL
+
+// RUN: %clang_cc1 -E -f__FILE__-prefix-to-remove=%s.xyz %s | FileCheck %s --check-prefix=ALL --check-prefix=MISMATCH
+// RUN: %clang -E -f__FILE__-prefix-to-remove= %s | FileCheck %s --check-prefix=ALL --check-prefix=MISMATCH
+
+const char *filename (const char *name) {
+  // ALL:  static const char this_file_basename[] = "file_basename.c";
+  static const char this_file_basename[] = __CLANG_FILE_BASENAME__;
+  // DEFAULT: static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  // NO-DIR:  static const char this_file[] = "file_basename.c";
+  // REMOVE-ALL: static const char this_file[] = "";
+  // MISMATCH: static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  static const char this_file[] = __FILE__;
+  return this_file;
+}
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -12,7 +12,6 @@
 //
 //===--===//
 
-#include "clang/Lex/Preprocessor.h"
 #include "clang/Basic/Attributes.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
@@ -22,12 +21,15 @@
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -292,6 +294,8 @@
 void Preprocessor::RegisterBuiltinMacros() {
   Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
   Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");
+  Ident__CLANG_FILE_BASENAME__ =
+  RegisterBuiltinMacro(*this, "__CLANG_FILE_BASENAME__");
   Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");
   Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
   Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
@@ -1509,7 +1513,8 @@
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(tok::numeric_constant);
-  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
+  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
+ II == Ident__CLANG_FILE_BASENAME__) {
 // C99 6.10.8: "__FILE__: The presumed name of the current source file (a
 // character string literal)". This can be affected by #line.
 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
@@ -1522,15 +1527,28 @@
 PLoc = SourceMgr.getPresumedLoc(NextLoc);
 if (PLoc.isInvalid())
   break;
-
 NextLoc = PLoc.getIncludeLoc();
   }
 }
 
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
 SmallString<128> FN;
 if (PLoc.isValid()) {
-  FN += PLoc.getFilename();
+  const std::string &PrefixToRemove =
+  getPreprocessorOpts().__FILE__PrefixToRemove;
+  StringRef Filename(PLoc.getFilename());
+  if (II == Ident__CLANG_FILE_BASENAME__)
+FN += llvm::sys::path::filename(Filename);
+  else if (II == Ident__FILE__ && !PrefixToRemove.empty()) {
+if (PrefixToRemove == "__ALL_DIR__")
+  FN += llvm::sys::path::filename(Filename);
+else if (Filename.find(PrefixToRemove) == 0)
+  FN += Filename.substr(PrefixToRemove.size());
+else
+  FN += Filename;
+  } else
+FN += Filename;
+
   Lexer::String

Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-03-03 Thread Weiming Zhao via cfe-commits
weimingz updated the summary for this revision.
weimingz updated this revision to Diff 49762.
weimingz added a comment.

Change the option name to -ffile-macro-prefix-to-remove


http://reviews.llvm.org/D17741

Files:
  include/clang/Driver/Options.td
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/Lexer/file_basename.c

Index: test/Lexer/file_basename.c
===
--- /dev/null
+++ test/Lexer/file_basename.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -E %s | FileCheck %s --check-prefix=ALL --check-prefix=DEFAULT
+
+// RUN: %clang_cc1 -E -ffile-macro-prefix-to-remove=__ALL_DIR__ %s | FileCheck %s --check-prefix=ALL --check-prefix=NO-DIR
+// RUN:%clang -E -ffile-macro-prefix-to-remove=__ALL_DIR__ %s | FileCheck %s --check-prefix=ALL --check-prefix=NO-DIR
+
+// RUN: %clang_cc1 -E -ffile-macro-prefix-to-remove=%s %s | FileCheck %s --check-prefix=ALL --check-prefix=REMOVE-ALL
+// RUN: %clang -E -ffile-macro-prefix-to-remove=%s %s | FileCheck %s --check-prefix=ALL --check-prefix=REMOVE-ALL
+
+// RUN: %clang_cc1 -E -ffile-macro-prefix-to-remove=%s.xyz %s | FileCheck %s --check-prefix=ALL --check-prefix=MISMATCH
+// RUN: %clang -E -ffile-macro-prefix-to-remove= %s | FileCheck %s --check-prefix=ALL --check-prefix=MISMATCH
+
+const char *filename (const char *name) {
+  // ALL:  static const char this_file_basename[] = "file_basename.c";
+  static const char this_file_basename[] = __CLANG_FILE_BASENAME__;
+  // DEFAULT: static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  // NO-DIR:  static const char this_file[] = "file_basename.c";
+  // REMOVE-ALL: static const char this_file[] = "";
+  // MISMATCH: static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  static const char this_file[] = __FILE__;
+  return this_file;
+}
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -12,7 +12,6 @@
 //
 //===--===//
 
-#include "clang/Lex/Preprocessor.h"
 #include "clang/Basic/Attributes.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
@@ -22,12 +21,15 @@
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -292,6 +294,8 @@
 void Preprocessor::RegisterBuiltinMacros() {
   Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
   Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");
+  Ident__CLANG_FILE_BASENAME__ =
+  RegisterBuiltinMacro(*this, "__CLANG_FILE_BASENAME__");
   Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");
   Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
   Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
@@ -1509,7 +1513,8 @@
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(tok::numeric_constant);
-  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
+  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
+ II == Ident__CLANG_FILE_BASENAME__) {
 // C99 6.10.8: "__FILE__: The presumed name of the current source file (a
 // character string literal)". This can be affected by #line.
 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
@@ -1522,15 +1527,30 @@
 PLoc = SourceMgr.getPresumedLoc(NextLoc);
 if (PLoc.isInvalid())
   break;
-
 NextLoc = PLoc.getIncludeLoc();
   }
 }
 
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
 SmallString<128> FN;
 if (PLoc.isValid()) {
-  FN += PLoc.getFilename();
+  const std::string &PrefixToRemove =
+  getPreprocessorOpts().__FILE__PrefixToRemove;
+  StringRef Filename(PLoc.getFilename());
+
+  if (II == Ident__CLANG_FILE_BASENAME__)
+FN += llvm::sys::path::filename(Filename);
+  else if (II == Ident__FILE__ && !PrefixToRemove.empty()) {
+if (PrefixToRemove == "__ALL_DIR__") {
+  FN += llvm::sys::path::filename(Filename);
+}
+else if (Filename.find(PrefixToRemove) == 0)
+  FN += Filename.substr(PrefixToRemove.size());
+else
+  FN += Filename;
+  } else
+FN += Filename;
+
   Lexer::Stringify(FN);
   OS << '"' << FN << '"';
 }
Index: lib/Frontend/CompilerInvocation.cpp

Re: [PATCH] D17874: Switch krait to use -mcpu=cortex-a15 for assembler tool invocations.

2016-03-03 Thread Weiming Zhao via cfe-commits
weimingz added a reviewer: apazos.
weimingz added a comment.

LGTM. Ana, could you take a look too?


http://reviews.llvm.org/D17874



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


Re: [PATCH] D17874: Switch krait to use -mcpu=cortex-a15 for assembler tool invocations.

2016-03-04 Thread Weiming Zhao via cfe-commits
weimingz accepted this revision.
weimingz added a comment.
This revision is now accepted and ready to land.

Ana is OK with it.


http://reviews.llvm.org/D17874



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


Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-03-10 Thread Weiming Zhao via cfe-commits
weimingz updated this revision to Diff 50300.
weimingz added a comment.

rebased


http://reviews.llvm.org/D17741

Files:
  include/clang/Driver/Options.td
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/Lexer/file_basename.c

Index: test/Lexer/file_basename.c
===
--- /dev/null
+++ test/Lexer/file_basename.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -E %s | FileCheck %s --check-prefix=ALL --check-prefix=DEFAULT
+
+// RUN: %clang_cc1 -E -ffile-macro-prefix-to-remove=__ALL_DIR__ %s | FileCheck %s --check-prefix=ALL --check-prefix=NO-DIR
+// RUN:%clang -E -ffile-macro-prefix-to-remove=__ALL_DIR__ %s | FileCheck %s --check-prefix=ALL --check-prefix=NO-DIR
+
+// RUN: %clang_cc1 -E -ffile-macro-prefix-to-remove=%s %s | FileCheck %s --check-prefix=ALL --check-prefix=REMOVE-ALL
+// RUN: %clang -E -ffile-macro-prefix-to-remove=%s %s | FileCheck %s --check-prefix=ALL --check-prefix=REMOVE-ALL
+
+// RUN: %clang_cc1 -E -ffile-macro-prefix-to-remove=%s.xyz %s | FileCheck %s --check-prefix=ALL --check-prefix=MISMATCH
+// RUN: %clang -E -ffile-macro-prefix-to-remove= %s | FileCheck %s --check-prefix=ALL --check-prefix=MISMATCH
+
+const char *filename (const char *name) {
+  // ALL:  static const char this_file_basename[] = "file_basename.c";
+  static const char this_file_basename[] = __CLANG_FILE_BASENAME__;
+  // DEFAULT: static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  // NO-DIR:  static const char this_file[] = "file_basename.c";
+  // REMOVE-ALL: static const char this_file[] = "";
+  // MISMATCH: static const char this_file[] = "{{.*}}/Lexer/file_basename.c";
+  static const char this_file[] = __FILE__;
+  return this_file;
+}
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -12,7 +12,6 @@
 //
 //===--===//
 
-#include "clang/Lex/Preprocessor.h"
 #include "clang/Basic/Attributes.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
@@ -22,12 +21,15 @@
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -292,6 +294,8 @@
 void Preprocessor::RegisterBuiltinMacros() {
   Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
   Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");
+  Ident__CLANG_FILE_BASENAME__ =
+  RegisterBuiltinMacro(*this, "__CLANG_FILE_BASENAME__");
   Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");
   Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
   Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
@@ -1509,7 +1513,8 @@
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(tok::numeric_constant);
-  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
+  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
+ II == Ident__CLANG_FILE_BASENAME__) {
 // C99 6.10.8: "__FILE__: The presumed name of the current source file (a
 // character string literal)". This can be affected by #line.
 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
@@ -1522,15 +1527,30 @@
 PLoc = SourceMgr.getPresumedLoc(NextLoc);
 if (PLoc.isInvalid())
   break;
-
 NextLoc = PLoc.getIncludeLoc();
   }
 }
 
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
 SmallString<128> FN;
 if (PLoc.isValid()) {
-  FN += PLoc.getFilename();
+  const std::string &PrefixToRemove =
+  getPreprocessorOpts().__FILE__PrefixToRemove;
+  StringRef Filename(PLoc.getFilename());
+
+  if (II == Ident__CLANG_FILE_BASENAME__)
+FN += llvm::sys::path::filename(Filename);
+  else if (II == Ident__FILE__ && !PrefixToRemove.empty()) {
+if (PrefixToRemove == "__ALL_DIR__") {
+  FN += llvm::sys::path::filename(Filename);
+}
+else if (Filename.find(PrefixToRemove) == 0)
+  FN += Filename.substr(PrefixToRemove.size());
+else
+  FN += Filename;
+  } else
+FN += Filename;
+
   Lexer::Stringify(FN);
   OS << '"' << FN << '"';
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.

Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-03-14 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

In http://reviews.llvm.org/D17741#372098, @weimingz wrote:

> rebased


ping~


http://reviews.llvm.org/D17741



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


Re: [PATCH] D17741: adds __FILE_BASENAME__ builtin macro

2016-03-21 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

In http://reviews.llvm.org/D17741#374725, @weimingz wrote:

> In http://reviews.llvm.org/D17741#372098, @weimingz wrote:
>
> > rebased
>
>
> ping~


HI,

Any comments/suggestions?


http://reviews.llvm.org/D17741



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


[PATCH] D16171: Warning on redeclaring with a conflicting asm label

2016-01-13 Thread Weiming Zhao via cfe-commits
weimingz created this revision.
weimingz added a reviewer: nicholas.
weimingz added a subscriber: cfe-commits.

r255371 errors on redeclaring with a conflicting asm label.
This patch changes errors to warnings to prevent breaking existing codes.

http://reviews.llvm.org/D16171

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  test/Sema/asm-label.c

Index: test/Sema/asm-label.c
===
--- test/Sema/asm-label.c
+++ test/Sema/asm-label.c
@@ -7,21 +7,21 @@
 void f() {
   g();
 }
-void g() __asm__("gold");  // expected-error{{cannot apply asm label to 
function after its first use}}
+void g() __asm__("gold");  // expected-warning{{cannot apply asm label to 
function after its first use}}
 
 void h() __asm__("hose");  // expected-note{{previous declaration is here}}
-void h() __asm__("hair");  // expected-error{{conflicting asm label}}
+void h() __asm__("hair");  // expected-warning{{conflicting asm label}}
 
 int x;
 int x __asm__("xenon");
 int y;
 
 int test() { return y; }
 
-int y __asm__("yacht");  // expected-error{{cannot apply asm label to variable 
after its first use}}
+int y __asm__("yacht");  // expected-warning{{cannot apply asm label to 
variable after its first use}}
 
 int z __asm__("zebra");  // expected-note{{previous declaration is here}}
-int z __asm__("zooms");  // expected-error{{conflicting asm label}}
+int z __asm__("zooms");  // expected-warning{{conflicting asm label}}
 
 
 // No diagnostics on the following.
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2385,13 +2385,13 @@
 if (AsmLabelAttr *OldA = Old->getAttr()) {
   if (OldA->getLabel() != NewA->getLabel()) {
 // This redeclaration changes __asm__ label.
-Diag(New->getLocation(), diag::err_different_asm_label);
+Diag(New->getLocation(), diag::warn_different_asm_label);
 Diag(OldA->getLocation(), diag::note_previous_declaration);
   }
 } else if (Old->isUsed()) {
   // This redeclaration adds an __asm__ label to a declaration that has
   // already been ODR-used.
-  Diag(New->getLocation(), diag::err_late_asm_label_name)
+  Diag(New->getLocation(), diag::warn_late_asm_label_name)
 << isa(Old) << New->getAttr()->getRange();
 }
   }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -4266,9 +4266,11 @@
 def err_conflicting_types : Error<"conflicting types for %0">;
 def err_different_pass_object_size_params : Error<
   "conflicting pass_object_size attributes on parameters">;
-def err_late_asm_label_name : Error<
-  "cannot apply asm label to %select{variable|function}0 after its first use">;
-def err_different_asm_label : Error<"conflicting asm label">;
+def warn_late_asm_label_name : Warning<
+  "cannot apply asm label to %select{variable|function}0 after its first use">,
+  InGroup;
+def warn_different_asm_label : Warning<"conflicting asm label">,
+  InGroup;
 def err_nested_redefinition : Error<"nested redefinition of %0">;
 def err_use_with_wrong_tag : Error<
   "use of %0 with tag type that does not match previous declaration">;


Index: test/Sema/asm-label.c
===
--- test/Sema/asm-label.c
+++ test/Sema/asm-label.c
@@ -7,21 +7,21 @@
 void f() {
   g();
 }
-void g() __asm__("gold");  // expected-error{{cannot apply asm label to function after its first use}}
+void g() __asm__("gold");  // expected-warning{{cannot apply asm label to function after its first use}}
 
 void h() __asm__("hose");  // expected-note{{previous declaration is here}}
-void h() __asm__("hair");  // expected-error{{conflicting asm label}}
+void h() __asm__("hair");  // expected-warning{{conflicting asm label}}
 
 int x;
 int x __asm__("xenon");
 int y;
 
 int test() { return y; }
 
-int y __asm__("yacht");  // expected-error{{cannot apply asm label to variable after its first use}}
+int y __asm__("yacht");  // expected-warning{{cannot apply asm label to variable after its first use}}
 
 int z __asm__("zebra");  // expected-note{{previous declaration is here}}
-int z __asm__("zooms");  // expected-error{{conflicting asm label}}
+int z __asm__("zooms");  // expected-warning{{conflicting asm label}}
 
 
 // No diagnostics on the following.
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2385,13 +2385,13 @@
 if (AsmLabelAttr *OldA = Old->getAttr()) {
   if (OldA->getLabel() != NewA->getLabel()) {
 // This redeclaration changes __asm__ label.
-Diag(New->getLocation(), diag::err_different_asm_label);
+Diag(New->getLocation(), diag::warn_dif

Re: [PATCH] D16171: Warning on redeclaring with a conflicting asm label

2016-01-14 Thread Weiming Zhao via cfe-commits
weimingz added a comment.

Hi Nick,

Below is a reduced code:
t.c:

  static long double acoshl (long double __x) __asm__ ("" "acosh") ;  // this 
is from /arm-linux-gnueabi/libc/usr/include/bits/mathcalls.h
  extern long double acoshl (long double) __asm__ ("" "__acoshl_finite") ; // 
this is from existing code

GCC gives warning like:
/tmp/t.c:2:1: warning: asm declaration ignored due to conflict with previous 
rename [-Wpragmas]
 extern long double acoshl (long double) __asm__ ("" "__acoshl_finite") ;


http://reviews.llvm.org/D16171



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


Re: [PATCH] D16171: Warning on redeclaring with a conflicting asm label

2016-01-14 Thread Weiming Zhao via cfe-commits
weimingz updated this revision to Diff 44931.
weimingz added a comment.

if the new decl is not used, we can just give warnings


http://reviews.llvm.org/D16171

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  test/Sema/asm-label.c

Index: test/Sema/asm-label.c
===
--- test/Sema/asm-label.c
+++ test/Sema/asm-label.c
@@ -10,7 +10,7 @@
 void g() __asm__("gold");  // expected-error{{cannot apply asm label to 
function after its first use}}
 
 void h() __asm__("hose");  // expected-note{{previous declaration is here}}
-void h() __asm__("hair");  // expected-error{{conflicting asm label}}
+void h() __asm__("hair");  // expected-warning{{conflicting asm label}}
 
 int x;
 int x __asm__("xenon");
@@ -21,7 +21,7 @@
 int y __asm__("yacht");  // expected-error{{cannot apply asm label to variable 
after its first use}}
 
 int z __asm__("zebra");  // expected-note{{previous declaration is here}}
-int z __asm__("zooms");  // expected-error{{conflicting asm label}}
+int z __asm__("zooms");  // expected-warning{{conflicting asm label}}
 
 
 // No diagnostics on the following.
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2385,7 +2385,10 @@
 if (AsmLabelAttr *OldA = Old->getAttr()) {
   if (OldA->getLabel() != NewA->getLabel()) {
 // This redeclaration changes __asm__ label.
-Diag(New->getLocation(), diag::err_different_asm_label);
+if (New->isUsed())
+  Diag(New->getLocation(), diag::err_different_asm_label);
+else
+  Diag(New->getLocation(), diag::warn_different_asm_label);
 Diag(OldA->getLocation(), diag::note_previous_declaration);
   }
 } else if (Old->isUsed()) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -4272,6 +4272,8 @@
 def err_nested_redefinition : Error<"nested redefinition of %0">;
 def err_use_with_wrong_tag : Error<
   "use of %0 with tag type that does not match previous declaration">;
+def warn_different_asm_label : Warning<"conflicting asm label">,
+InGroup;
 def warn_struct_class_tag_mismatch : Warning<
 "%select{struct|interface|class}0%select{| template}1 %2 was previously "
 "declared as a %select{struct|interface|class}3%select{| template}1">,


Index: test/Sema/asm-label.c
===
--- test/Sema/asm-label.c
+++ test/Sema/asm-label.c
@@ -10,7 +10,7 @@
 void g() __asm__("gold");  // expected-error{{cannot apply asm label to function after its first use}}
 
 void h() __asm__("hose");  // expected-note{{previous declaration is here}}
-void h() __asm__("hair");  // expected-error{{conflicting asm label}}
+void h() __asm__("hair");  // expected-warning{{conflicting asm label}}
 
 int x;
 int x __asm__("xenon");
@@ -21,7 +21,7 @@
 int y __asm__("yacht");  // expected-error{{cannot apply asm label to variable after its first use}}
 
 int z __asm__("zebra");  // expected-note{{previous declaration is here}}
-int z __asm__("zooms");  // expected-error{{conflicting asm label}}
+int z __asm__("zooms");  // expected-warning{{conflicting asm label}}
 
 
 // No diagnostics on the following.
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2385,7 +2385,10 @@
 if (AsmLabelAttr *OldA = Old->getAttr()) {
   if (OldA->getLabel() != NewA->getLabel()) {
 // This redeclaration changes __asm__ label.
-Diag(New->getLocation(), diag::err_different_asm_label);
+if (New->isUsed())
+  Diag(New->getLocation(), diag::err_different_asm_label);
+else
+  Diag(New->getLocation(), diag::warn_different_asm_label);
 Diag(OldA->getLocation(), diag::note_previous_declaration);
   }
 } else if (Old->isUsed()) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -4272,6 +4272,8 @@
 def err_nested_redefinition : Error<"nested redefinition of %0">;
 def err_use_with_wrong_tag : Error<
   "use of %0 with tag type that does not match previous declaration">;
+def warn_different_asm_label : Warning<"conflicting asm label">,
+InGroup;
 def warn_struct_class_tag_mismatch : Warning<
 "%select{struct|interface|class}0%select{| template}1 %2 was previously "
 "declared as a %select{struct|interface|class}3%select{| template}1">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits