[libunwind] r343990 - [CMake] Link to compiler-rt if LIBUNWIND_USE_COMPILER_RT is ON.

2018-10-08 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Mon Oct  8 11:35:00 2018
New Revision: 343990

URL: http://llvm.org/viewvc/llvm-project?rev=343990&view=rev
Log:
[CMake] Link to compiler-rt if LIBUNWIND_USE_COMPILER_RT is ON.

Summary:
If `-nodefaultlibs` is given, we weren't actually linking to it. This
was true irrespective of passing `-rtlib=compiler-rt` (see previous
patch). Now we explicitly link it to handle that case.

I wonder if we should be linking these libraries only if we're using
`-nodefaultlibs`...

Reviewers: beanz

Subscribers: dberris, mgorny, christof, chrib, cfe-commits

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

Modified:
libunwind/trunk/cmake/config-ix.cmake
libunwind/trunk/src/CMakeLists.txt

Modified: libunwind/trunk/cmake/config-ix.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/cmake/config-ix.cmake?rev=343990&r1=343989&r2=343990&view=diff
==
--- libunwind/trunk/cmake/config-ix.cmake (original)
+++ libunwind/trunk/cmake/config-ix.cmake Mon Oct  8 11:35:00 2018
@@ -7,6 +7,7 @@ check_library_exists(c fopen "" LIBUNWIN
 
 if (NOT LIBUNWIND_USE_COMPILER_RT)
   check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB)
+  check_library_exists(gcc __absvdi2 "" LIBUNWIND_HAS_GCC_LIB)
 endif()
 
 # libunwind is built with -nodefaultlibs, so we want all our checks to also
@@ -25,8 +26,13 @@ if (LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
   if (LIBUNWIND_USE_COMPILER_RT)
 find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY)
 list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}")
-  elseif (LIBUNWIND_HAS_GCC_S_LIB)
-list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
+  else ()
+if (LIBUNWIND_HAS_GCC_S_LIB)
+  list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
+endif ()
+if (LIBUNWIND_HAS_GCC_LIB)
+  list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
+endif ()
   endif ()
   if (MINGW)
 # Mingw64 requires quite a few "C" runtime libraries in order for basic

Modified: libunwind/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/CMakeLists.txt?rev=343990&r1=343989&r2=343990&view=diff
==
--- libunwind/trunk/src/CMakeLists.txt (original)
+++ libunwind/trunk/src/CMakeLists.txt Mon Oct  8 11:35:00 2018
@@ -53,7 +53,12 @@ set(LIBUNWIND_SOURCES
 # Generate library list.
 set(libraries)
 append_if(libraries LIBUNWIND_HAS_C_LIB c)
-append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s)
+if (LIBUNWIND_USE_COMPILER_RT)
+  list(APPEND libraries "${LIBUNWIND_BUILTINS_LIBRARY}")
+else()
+  append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s)
+  append_if(libraries LIBUNWIND_HAS_GCC_LIB gcc)
+endif()
 append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
 if (LIBUNWIND_ENABLE_THREADS)
   append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)


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


[libunwind] r341404 - [CMake] Don't use -rtlib=compiler-rt with -nodefaultlibs.

2018-09-04 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Tue Sep  4 13:57:50 2018
New Revision: 341404

URL: http://llvm.org/viewvc/llvm-project?rev=341404&view=rev
Log:
[CMake] Don't use -rtlib=compiler-rt with -nodefaultlibs.

Summary:
This switch only has an effect at link time. It changes the default
compiler support library to `compiler-rt`. With `-nodefaultlibs`, this
library won't get linked anyway; Clang actually warns about that.

Reviewers: mstorsjo, rnk

Subscribers: dberris, mgorny, christof, cfe-commits

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

Modified:
libunwind/trunk/CMakeLists.txt
libunwind/trunk/cmake/config-ix.cmake

Modified: libunwind/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/CMakeLists.txt?rev=341404&r1=341403&r2=341404&view=diff
==
--- libunwind/trunk/CMakeLists.txt (original)
+++ libunwind/trunk/CMakeLists.txt Tue Sep  4 13:57:50 2018
@@ -234,7 +234,7 @@ endif()
 # Configure compiler.
 include(config-ix)
 
-if (LIBUNWIND_USE_COMPILER_RT)
+if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
   list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
 endif()
 

Modified: libunwind/trunk/cmake/config-ix.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/cmake/config-ix.cmake?rev=341404&r1=341403&r2=341404&view=diff
==
--- libunwind/trunk/cmake/config-ix.cmake (original)
+++ libunwind/trunk/cmake/config-ix.cmake Tue Sep  4 13:57:50 2018
@@ -23,7 +23,6 @@ if (LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
 list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
   if (LIBUNWIND_USE_COMPILER_RT)
-list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt)
 find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY)
 list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}")
   elseif (LIBUNWIND_HAS_GCC_S_LIB)


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


[libunwind] r341388 - [CMake] Remove variable reference that isn't used.

2018-09-04 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Tue Sep  4 10:40:26 2018
New Revision: 341388

URL: http://llvm.org/viewvc/llvm-project?rev=341388&view=rev
Log:
[CMake] Remove variable reference that isn't used.

Summary:
This variable is never defined, so its value is always empty. Since
`libunwind` is needed to build the C++ ABI library in the first place,
it should never be linked to the C++ ABI library anyway.

Reviewers: mstorsjo, rnk

Subscribers: mgorny, christof, cfe-commits

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

Modified:
libunwind/trunk/src/CMakeLists.txt

Modified: libunwind/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/CMakeLists.txt?rev=341388&r1=341387&r2=341388&view=diff
==
--- libunwind/trunk/src/CMakeLists.txt (original)
+++ libunwind/trunk/src/CMakeLists.txt Tue Sep  4 10:40:26 2018
@@ -51,7 +51,7 @@ set(LIBUNWIND_SOURCES
 ${LIBUNWIND_ASM_SOURCES})
 
 # Generate library list.
-set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES})
+set(libraries)
 append_if(libraries LIBUNWIND_HAS_C_LIB c)
 append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s)
 append_if(libraries LIBUNWIND_HAS_DL_LIB dl)


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


[libunwind] r341232 - Export public functions implemented in assembly on Windows.

2018-08-31 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Fri Aug 31 11:11:48 2018
New Revision: 341232

URL: http://llvm.org/viewvc/llvm-project?rev=341232&view=rev
Log:
Export public functions implemented in assembly on Windows.

Summary:
By default, symbols aren't visible outside of the module that defines
them. To make them visible, they must be exported. The easiest way to do
that is to embed an `-export:symname` directive into the object file.

Reviewers: mstorsjo, rnk

Subscribers: christof, cfe-commits

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

Modified:
libunwind/trunk/src/assembly.h

Modified: libunwind/trunk/src/assembly.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/assembly.h?rev=341232&r1=341231&r2=341232&view=diff
==
--- libunwind/trunk/src/assembly.h (original)
+++ libunwind/trunk/src/assembly.h Fri Aug 31 11:11:48 2018
@@ -44,6 +44,7 @@
 #if defined(__APPLE__)
 
 #define SYMBOL_IS_FUNC(name)
+#define EXPORT_SYMBOL(name)
 #define HIDDEN_SYMBOL(name) .private_extern name
 #define NO_EXEC_STACK_DIRECTIVE
 
@@ -54,6 +55,7 @@
 #else
 #define SYMBOL_IS_FUNC(name) .type name,@function
 #endif
+#define EXPORT_SYMBOL(name)
 #define HIDDEN_SYMBOL(name) .hidden name
 
 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
@@ -70,6 +72,11 @@
 .scl 2 SEPARATOR   
\
 .type 32 SEPARATOR 
\
   .endef
+#define EXPORT_SYMBOL2(name)  \
+  .section .drectve,"yn" SEPARATOR\
+  .ascii "-export:", #name, "\0" SEPARATOR\
+  .text
+#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
 #define HIDDEN_SYMBOL(name)
 
 #define NO_EXEC_STACK_DIRECTIVE
@@ -82,6 +89,7 @@
 
 #define DEFINE_LIBUNWIND_FUNCTION(name)   \
   .globl SYMBOL_NAME(name) SEPARATOR  \
+  EXPORT_SYMBOL(name) SEPARATOR   \
   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
   SYMBOL_NAME(name):
 


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


[libunwind] r341210 - [AddressSpace] Use the macro to set hidden visibility on LocalAddressSpace.

2018-08-31 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Fri Aug 31 06:41:05 2018
New Revision: 341210

URL: http://llvm.org/viewvc/llvm-project?rev=341210&view=rev
Log:
[AddressSpace] Use the macro to set hidden visibility on LocalAddressSpace.

Summary:
That attribute has no effect on Windows anyway--classes are hidden by
default.

Reviewers: mstorsjo, rnk

Subscribers: christof, cfe-commits

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

Modified:
libunwind/trunk/src/AddressSpace.hpp

Modified: libunwind/trunk/src/AddressSpace.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/AddressSpace.hpp?rev=341210&r1=341209&r2=341210&view=diff
==
--- libunwind/trunk/src/AddressSpace.hpp (original)
+++ libunwind/trunk/src/AddressSpace.hpp Fri Aug 31 06:41:05 2018
@@ -180,7 +180,7 @@ struct UnwindInfoSections {
 /// LocalAddressSpace is used as a template parameter to UnwindCursor when
 /// unwinding a thread in the same process.  The wrappers compile away,
 /// making local unwinds fast.
-class __attribute__((visibility("hidden"))) LocalAddressSpace {
+class _LIBUNWIND_HIDDEN LocalAddressSpace {
 public:
   typedef uintptr_t pint_t;
   typedef intptr_t  sint_t;


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


[libunwind] r341125 - Add support for SEH unwinding on Windows.

2018-08-30 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Thu Aug 30 14:29:00 2018
New Revision: 341125

URL: http://llvm.org/viewvc/llvm-project?rev=341125&view=rev
Log:
Add support for SEH unwinding on Windows.

Summary:
I've tested this implementation on x86-64 to ensure that it works. All
`libc++abi` tests pass, as do all `libc++` exception-related tests. ARM
still remains to be implemented (@compnerd?).

Special thanks to KJK::Hyperion for his excellent series of articles on
how EH works on x86-64 Windows. (Seriously, check it out. It's awesome.)

I'm actually not sure if this should go in as is. I particularly don't
like that I duplicated the UnwindCursor class for this special case.

Reviewers: mstorsjo, rnk, compnerd, smeenai, javed.absar

Subscribers: mgorny, kristof.beyls, christof, chrib, cfe-commits, compnerd, 
llvm-commits

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

Added:
libunwind/trunk/src/Unwind-seh.cpp
Modified:
libunwind/trunk/include/__libunwind_config.h
libunwind/trunk/include/unwind.h
libunwind/trunk/src/AddressSpace.hpp
libunwind/trunk/src/CMakeLists.txt
libunwind/trunk/src/UnwindCursor.hpp
libunwind/trunk/src/UnwindLevel1-gcc-ext.c
libunwind/trunk/src/UnwindLevel1.c
libunwind/trunk/src/config.h

Modified: libunwind/trunk/include/__libunwind_config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/__libunwind_config.h?rev=341125&r1=341124&r2=341125&view=diff
==
--- libunwind/trunk/include/__libunwind_config.h (original)
+++ libunwind/trunk/include/__libunwind_config.h Thu Aug 30 14:29:00 2018
@@ -34,7 +34,11 @@
 #  define _LIBUNWIND_TARGET_X86_64 1
 #  if defined(_WIN64)
 #define _LIBUNWIND_CONTEXT_SIZE 54
-#define _LIBUNWIND_CURSOR_SIZE 66
+#ifdef __SEH__
+#  define _LIBUNWIND_CURSOR_SIZE 204
+#else
+#  define _LIBUNWIND_CURSOR_SIZE 66
+#endif
 #  else
 #define _LIBUNWIND_CONTEXT_SIZE 21
 #define _LIBUNWIND_CURSOR_SIZE 33
@@ -57,7 +61,10 @@
 #  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 
_LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64
 # elif defined(__arm__)
 #  define _LIBUNWIND_TARGET_ARM 1
-#  if defined(__ARM_WMMX)
+#  if defined(__SEH__)
+#define _LIBUNWIND_CONTEXT_SIZE 42
+#define _LIBUNWIND_CURSOR_SIZE 85
+#  elif defined(__ARM_WMMX)
 #define _LIBUNWIND_CONTEXT_SIZE 61
 #define _LIBUNWIND_CURSOR_SIZE 68
 #  else

Modified: libunwind/trunk/include/unwind.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/unwind.h?rev=341125&r1=341124&r2=341125&view=diff
==
--- libunwind/trunk/include/unwind.h (original)
+++ libunwind/trunk/include/unwind.h Thu Aug 30 14:29:00 2018
@@ -19,8 +19,9 @@
 #include 
 #include 
 
-#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) && defined(_WIN32)
 #include 
+#include 
 #endif
 
 #if defined(__APPLE__)
@@ -378,12 +379,19 @@ extern void *__deregister_frame_info_bas
 LIBUNWIND_UNAVAIL;
 
 #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#ifndef _WIN32
+typedef struct _EXCEPTION_RECORD EXCEPTION_RECORD;
+typedef struct _CONTEXT CONTEXT;
+typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT;
+#elif !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000
+typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT;
+#endif
 // This is the common wrapper for GCC-style personality functions with SEH.
-extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
-   PVOID frame,
-   PCONTEXT ctx,
-   PDISPATCHER_CONTEXT disp,
-   _Unwind_Personality_Fn 
pers);
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(EXCEPTION_RECORD *exc,
+   void *frame,
+   CONTEXT *ctx,
+   DISPATCHER_CONTEXT *disp,
+   __personality_routine pers);
 #endif
 
 #ifdef __cplusplus

Modified: libunwind/trunk/src/AddressSpace.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/AddressSpace.hpp?rev=341125&r1=341124&r2=341125&view=diff
==
--- libunwind/trunk/src/AddressSpace.hpp (original)
+++ libunwind/trunk/src/AddressSpace.hpp Thu Aug 30 14:29:00 2018
@@ -155,7 +155,7 @@ namespace libunwind {
 struct UnwindInfoSections {
 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) || 
defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) ||   \
 defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
-  // No dso_base for ARM EHABI.
+  // No dso_base for SEH or ARM EHABI.
   uintptr_t   dso_base;
 #endif
 #if defined(_LIB

[libunwind] r339259 - Remove unneeded preprocessor condition.

2018-08-08 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Wed Aug  8 08:18:22 2018
New Revision: 339259

URL: http://llvm.org/viewvc/llvm-project?rev=339259&view=rev
Log:
Remove unneeded preprocessor condition.

Modified:
libunwind/trunk/include/unwind.h

Modified: libunwind/trunk/include/unwind.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/unwind.h?rev=339259&r1=339258&r2=339259&view=diff
==
--- libunwind/trunk/include/unwind.h (original)
+++ libunwind/trunk/include/unwind.h Wed Aug  8 08:18:22 2018
@@ -379,20 +379,11 @@ extern void *__deregister_frame_info_bas
 
 #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
 // This is the common wrapper for GCC-style personality functions with SEH.
-#ifdef __x86_64__
-// The DISPATCHER_CONTEXT struct is only defined on x64.
 extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
PVOID frame,
PCONTEXT ctx,
PDISPATCHER_CONTEXT disp,
_Unwind_Personality_Fn 
pers);
-#else
-extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
-   PVOID frame,
-   PCONTEXT ctx,
-   PVOID disp,
-   _Unwind_Personality_Fn 
pers);
-#endif
 #endif
 
 #ifdef __cplusplus


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


[libunwind] r339258 - [libunwind][include] Add SEH declarations to .

2018-08-08 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Wed Aug  8 08:18:20 2018
New Revision: 339258

URL: http://llvm.org/viewvc/llvm-project?rev=339258&view=rev
Log:
[libunwind][include] Add SEH declarations to .

Summary:
Make the `_Unwind_Exception` struct correct under SEH. Add a
declaration of `_GCC_specific_handler()`, which is used by SEH versions
of Itanium personality handlers to do common setup. Roughly corresponds
to Clang's D50380.

Reviewers: mstorsjo, rnk, compnerd, smeenai

Subscribers: christof, chrib, cfe-commits, llvm-commits

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

Modified:
libunwind/trunk/include/unwind.h

Modified: libunwind/trunk/include/unwind.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/unwind.h?rev=339258&r1=339257&r2=339258&view=diff
==
--- libunwind/trunk/include/unwind.h (original)
+++ libunwind/trunk/include/unwind.h Wed Aug  8 08:18:20 2018
@@ -19,6 +19,10 @@
 #include 
 #include 
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#include 
+#endif
+
 #if defined(__APPLE__)
 #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
 #else
@@ -120,13 +124,17 @@ struct _Unwind_Exception {
   uint64_t exception_class;
   void (*exception_cleanup)(_Unwind_Reason_Code reason,
 _Unwind_Exception *exc);
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+  uintptr_t private_[6];
+#else
   uintptr_t private_1; // non-zero means forced unwind
   uintptr_t private_2; // holds sp that phase1 found for phase2 to use
+#endif
 #if __SIZEOF_POINTER__ == 4
   // The implementation of _Unwind_Exception uses an attribute mode on the
   // above fields which has the side effect of causing this whole struct to
-  // round up to 32 bytes in size. To be more explicit, we add pad fields
-  // added for binary compatibility.
+  // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
+  // pad fields added for binary compatibility.
   uint32_t reserved[3];
 #endif
   // The Itanium ABI requires that _Unwind_Exception objects are "double-word
@@ -369,6 +377,24 @@ extern void *__deregister_frame_info(con
 extern void *__deregister_frame_info_bases(const void *fde)
 LIBUNWIND_UNAVAIL;
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+// This is the common wrapper for GCC-style personality functions with SEH.
+#ifdef __x86_64__
+// The DISPATCHER_CONTEXT struct is only defined on x64.
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+   PCONTEXT ctx,
+   PDISPATCHER_CONTEXT disp,
+   _Unwind_Personality_Fn 
pers);
+#else
+extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD exc,
+   PVOID frame,
+   PCONTEXT ctx,
+   PVOID disp,
+   _Unwind_Personality_Fn 
pers);
+#endif
+#endif
+
 #ifdef __cplusplus
 }
 #endif


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


[libunwind] r339217 - [libunwind] Fix pointer-to-integer cast warnings on LLP64.

2018-08-07 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Tue Aug  7 21:21:24 2018
New Revision: 339217

URL: http://llvm.org/viewvc/llvm-project?rev=339217&view=rev
Log:
[libunwind] Fix pointer-to-integer cast warnings on LLP64.

Summary:
`long` is too short on LLP64. We have to use `intptr_t` to
avoid truncating pointers.

Reviewers: mstorsjo, rnk, compnerd, smeenai

Subscribers: christof, cfe-commits, llvm-commits

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

Modified:
libunwind/trunk/src/UnwindLevel1-gcc-ext.c
libunwind/trunk/src/UnwindLevel1.c

Modified: libunwind/trunk/src/UnwindLevel1-gcc-ext.c
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindLevel1-gcc-ext.c?rev=339217&r1=339216&r2=339217&view=diff
==
--- libunwind/trunk/src/UnwindLevel1-gcc-ext.c (original)
+++ libunwind/trunk/src/UnwindLevel1-gcc-ext.c Tue Aug  7 21:21:24 2018
@@ -33,9 +33,9 @@ _Unwind_Resume_or_Rethrow(_Unwind_Except
(void *)exception_object,
(long)exception_object->unwinder_cache.reserved1);
 #else
-  _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld",
+  _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" 
PRIdPTR,
(void *)exception_object,
-   (long)exception_object->private_1);
+   (intptr_t)exception_object->private_1);
 #endif
 
 #if defined(_LIBUNWIND_ARM_EHABI)
@@ -92,9 +92,9 @@ _LIBUNWIND_EXPORT void *_Unwind_FindEncl
   unw_proc_info_t info;
   unw_getcontext(&uc);
   unw_init_local(&cursor, &uc);
-  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);
+  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc);
   if (unw_get_proc_info(&cursor, &info) == UNW_ESUCCESS)
-return (void *)(long) info.start_ip;
+return (void *)(intptr_t) info.start_ip;
   else
 return NULL;
 }
@@ -190,14 +190,14 @@ _LIBUNWIND_EXPORT const void *_Unwind_Fi
   unw_proc_info_t info;
   unw_getcontext(&uc);
   unw_init_local(&cursor, &uc);
-  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);
+  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t) pc);
   unw_get_proc_info(&cursor, &info);
   bases->tbase = (uintptr_t)info.extra;
   bases->dbase = 0; // dbase not used on Mac OS X
   bases->func = (uintptr_t)info.start_ip;
   _LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p", pc,
-  (void *)(long) info.unwind_info);
-  return (void *)(long) info.unwind_info;
+  (void *)(intptr_t) info.unwind_info);
+  return (void *)(intptr_t) info.unwind_info;
 }
 
 /// Returns the CFA (call frame area, or stack pointer at start of function)

Modified: libunwind/trunk/src/UnwindLevel1.c
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindLevel1.c?rev=339217&r1=339216&r2=339217&view=diff
==
--- libunwind/trunk/src/UnwindLevel1.c (original)
+++ libunwind/trunk/src/UnwindLevel1.c Tue Aug  7 21:21:24 2018
@@ -287,7 +287,7 @@ unwind_phase2_forced(unw_context_t *uc,
 // If there is a personality routine, tell it we are unwinding.
 if (frameInfo.handler != 0) {
   __personality_routine p =
-  (__personality_routine)(long)(frameInfo.handler);
+  (__personality_routine)(intptr_t)(frameInfo.handler);
   _LIBUNWIND_TRACE_UNWINDING(
   "unwind_phase2_forced(ex_ojb=%p): calling personality function %p",
   (void *)exception_object, (void *)(uintptr_t)p);


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


r278052 - Revert "[Attr] Add support for the `ms_hook_prologue` attribute."

2016-08-08 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Mon Aug  8 16:19:08 2016
New Revision: 278052

URL: http://llvm.org/viewvc/llvm-project?rev=278052&view=rev
Log:
Revert "[Attr] Add support for the `ms_hook_prologue` attribute."

This reverts commit r278050. It depends on r278048, which will be
reverted.

Removed:
cfe/trunk/test/Sema/attr-ms-hook-prologue-wrong-arch.c
cfe/trunk/test/Sema/attr-ms-hook-prologue.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/CodeGen/function-attributes.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=278052&r1=278051&r2=278052&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Aug  8 16:19:08 2016
@@ -257,7 +257,6 @@ def TargetMips : TargetArch<["mips", "mi
 def TargetMSP430 : TargetArch<["msp430"]>;
 def TargetX86 : TargetArch<["x86"]>;
 def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
-def TargetWindowsArches : TargetArch<["x86", "x86_64", "arm", "thumb"]>;
 def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
   let OSes = ["Win32"];
 }
@@ -2070,12 +2069,6 @@ def TypeTagForDatatype : InheritableAttr
 
 // Microsoft-related attributes
 
-def MSHookPrologue : InheritableAttr, TargetSpecificAttr {
-  let Spellings = [GCC<"ms_hook_prologue">];
-  let Subjects = SubjectList<[Function]>;
-  let Documentation = [MSHookPrologueDocs];
-}
-
 def MSNoVTable : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"novtable">];
   let Subjects = SubjectList<[CXXRecord]>;

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=278052&r1=278051&r2=278052&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Mon Aug  8 16:19:08 2016
@@ -548,22 +548,6 @@ Query for this feature with ``__has_attr
   }];
 }
 
-def MSHookPrologueDocs : Documentation {
-  let Category = DocCatFunction;
-  let Content = [{
-The ``ms_hook_prologue`` attribute marks a function as "hotpatchable" according
-to conventions used on Windows. Specifically, enough space will be ensured
-in the prologue for a short jump, and an architecturally dependently sized
-patch space will be reserved prior to the entry point. See the documentation
-for the `/HOTPATCH`_ switch on MSDN.
-
-This attribute cannot be used in conjunction with the ``naked``,
-``always_inline``, or ``__forceinline`` attributes.
-
-.. _`/HOTPATCH`: https://msdn.microsoft.com/en-us/library/ms173507.aspx
-  }];
-}
-
 def NoDebugDocs : Documentation {
   let Category = DocCatVariable;
   let Content = [{

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=278052&r1=278051&r2=278052&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Aug  8 16:19:08 2016
@@ -1779,10 +1779,6 @@ void X86_32TargetCodeGenInfo::setTargetA
   llvm::Function *Fn = cast(GV);
   Fn->setCallingConv(llvm::CallingConv::X86_INTR);
 }
-if (FD->hasAttr()) {
-  llvm::Function *Fn = cast(GV);
-  Fn->addFnAttr("patchable-function", "ms-hotpatch");
-}
   }
 }
 
@@ -2113,10 +2109,6 @@ public:
 llvm::Function *Fn = cast(GV);
 Fn->setCallingConv(llvm::CallingConv::X86_INTR);
   }
-  if (FD->hasAttr()) {
-llvm::Function *Fn = cast(GV);
-Fn->addFnAttr("patchable-function", "ms-hotpatch");
-  }
 }
   }
 };

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=278052&r1=278051&r2=278052&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Aug  8 16:19:08 2016
@@ -1664,6 +1664,15 @@ static void handleCommonAttr(Sema &S, De
 D->addAttr(CA);
 }
 
+static void handleNakedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+  if (checkAttrMutualExclusion(S, D, Attr.getRange(),
+ Attr.getName()))
+return;
+
+  D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context,
+ 
Attr.getAttributeSpellingListIndex()));
+}
+
 static void handleNoReturnAttr(Sema &S, Decl *D, const AttributeList &attr) {
   if (hasDeclarator(D)) return;
 
@@ -3664,9 +3673,7 @@ OptimizeNoneAttr *Sema::mergeOptimizeNon
 static void handleAlwaysInlineAtt

r278050 - [Attr] Add support for the `ms_hook_prologue` attribute.

2016-08-08 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Mon Aug  8 16:03:39 2016
New Revision: 278050

URL: http://llvm.org/viewvc/llvm-project?rev=278050&view=rev
Log:
[Attr] Add support for the `ms_hook_prologue` attribute.

Summary:
Based on a patch by Michael Mueller.

This attribute specifies that a function can be hooked or patched. This
mechanism was originally devised by Microsoft for hotpatching their
binaries (which they're constantly updating to stay ahead of crackers,
script kiddies, and other ne'er-do-wells on the Internet), but it's now
commonly abused by Windows programs that want to hook API functions. It
is for this reason that this attribute was added to GCC--hence the name,
`ms_hook_prologue`.

Depends on D19908.

Reviewers: rnk, aaron.ballman

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Sema/attr-ms-hook-prologue-wrong-arch.c
cfe/trunk/test/Sema/attr-ms-hook-prologue.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/CodeGen/function-attributes.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=278050&r1=278049&r2=278050&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Aug  8 16:03:39 2016
@@ -257,6 +257,7 @@ def TargetMips : TargetArch<["mips", "mi
 def TargetMSP430 : TargetArch<["msp430"]>;
 def TargetX86 : TargetArch<["x86"]>;
 def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
+def TargetWindowsArches : TargetArch<["x86", "x86_64", "arm", "thumb"]>;
 def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
   let OSes = ["Win32"];
 }
@@ -2069,6 +2070,12 @@ def TypeTagForDatatype : InheritableAttr
 
 // Microsoft-related attributes
 
+def MSHookPrologue : InheritableAttr, TargetSpecificAttr {
+  let Spellings = [GCC<"ms_hook_prologue">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [MSHookPrologueDocs];
+}
+
 def MSNoVTable : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"novtable">];
   let Subjects = SubjectList<[CXXRecord]>;

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=278050&r1=278049&r2=278050&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Mon Aug  8 16:03:39 2016
@@ -548,6 +548,22 @@ Query for this feature with ``__has_attr
   }];
 }
 
+def MSHookPrologueDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``ms_hook_prologue`` attribute marks a function as "hotpatchable" according
+to conventions used on Windows. Specifically, enough space will be ensured
+in the prologue for a short jump, and an architecturally dependently sized
+patch space will be reserved prior to the entry point. See the documentation
+for the `/HOTPATCH`_ switch on MSDN.
+
+This attribute cannot be used in conjunction with the ``naked``,
+``always_inline``, or ``__forceinline`` attributes.
+
+.. _`/HOTPATCH`: https://msdn.microsoft.com/en-us/library/ms173507.aspx
+  }];
+}
+
 def NoDebugDocs : Documentation {
   let Category = DocCatVariable;
   let Content = [{

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=278050&r1=278049&r2=278050&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Aug  8 16:03:39 2016
@@ -1779,6 +1779,10 @@ void X86_32TargetCodeGenInfo::setTargetA
   llvm::Function *Fn = cast(GV);
   Fn->setCallingConv(llvm::CallingConv::X86_INTR);
 }
+if (FD->hasAttr()) {
+  llvm::Function *Fn = cast(GV);
+  Fn->addFnAttr("patchable-function", "ms-hotpatch");
+}
   }
 }
 
@@ -2109,6 +2113,10 @@ public:
 llvm::Function *Fn = cast(GV);
 Fn->setCallingConv(llvm::CallingConv::X86_INTR);
   }
+  if (FD->hasAttr()) {
+llvm::Function *Fn = cast(GV);
+Fn->addFnAttr("patchable-function", "ms-hotpatch");
+  }
 }
   }
 };

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=278050&r1=278049&r2=278050&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Aug  8 16:03:39 2016
@@ -1664,15 +1664,6 @@ static void handleCommonAttr(Sema &S, De
 D->addAttr(CA);
 }
 
-static void handleNakedAttr(Sema &S, Decl *D

Re: [PATCH] D19909: [Attr] Add support for the `ms_hook_prologue` attribute.

2016-08-03 Thread Charles Davis via cfe-commits
cdavis5x marked an inline comment as done.


Comment at: include/clang/Basic/AttrDocs.td:560
@@ +559,3 @@
+
+This attribute cannot be used in conjunction with the ``naked``,
+``always_inline``, or ``__forceinline`` attributes.

Done.


https://reviews.llvm.org/D19909



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


Re: [PATCH] D19909: [Attr] Add support for the `ms_hook_prologue` attribute.

2016-08-03 Thread Charles Davis via cfe-commits
cdavis5x updated this revision to Diff 66729.
cdavis5x added a comment.

Update for merge conflicts.

- Add a blurb to the docs advising against using this attribute with 
`__forceinline`, `always_inline`, or `naked`.


https://reviews.llvm.org/D19909

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/function-attributes.c
  test/Sema/attr-ms-hook-prologue-wrong-arch.c
  test/Sema/attr-ms-hook-prologue.c

Index: test/Sema/attr-ms-hook-prologue.c
===
--- /dev/null
+++ test/Sema/attr-ms-hook-prologue.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple i386-pc-linux -fms-extensions -fsyntax-only -verify %s
+
+int __attribute__((ms_hook_prologue)) foo(int a, int b) {
+  return a+b;
+}
+
+// expected-note@+2{{conflicting attribute is here}}
+// expected-error@+1{{'naked' and 'ms_hook_prologue' attributes are not compatible}}
+__declspec(naked) int __attribute__((ms_hook_prologue)) bar(int a, int b) {
+}
+
+// expected-note@+2{{conflicting attribute is here}}
+// expected-error@+1{{'__forceinline' and 'ms_hook_prologue' attributes are not compatible}}
+__forceinline int __attribute__((ms_hook_prologue)) baz(int a, int b) {
+  return a-b;
+}
+
+// expected-warning@+1{{'ms_hook_prologue' attribute only applies to functions}}
+int x __attribute__((ms_hook_prologue));
+
+// expected-error@+1{{'ms_hook_prologue' attribute takes no arguments}}
+int f(int a, int b) __attribute__((ms_hook_prologue(2)));
Index: test/Sema/attr-ms-hook-prologue-wrong-arch.c
===
--- /dev/null
+++ test/Sema/attr-ms-hook-prologue-wrong-arch.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple s390x-unknown-linux -fms-extensions -fsyntax-only -verify %s
+
+// expected-warning@+1{{unknown attribute 'ms_hook_prologue' ignored}}
+int __attribute__((ms_hook_prologue)) foo(int a, int b) {
+  return a+b;
+}
Index: test/CodeGen/function-attributes.c
===
--- test/CodeGen/function-attributes.c
+++ test/CodeGen/function-attributes.c
@@ -108,11 +108,18 @@
   _setjmp(0);
 }
 
+// CHECK-LABEL: define void @f21
+// CHECK: [[HOTPATCH:#[0-9]+]]
+// CHECK: {
+void __attribute__((ms_hook_prologue)) f21(void) {
+}
+
 // CHECK: attributes [[NUW]] = { nounwind optsize{{.*}} }
 // CHECK: attributes [[AI]] = { alwaysinline nounwind optsize{{.*}} }
 // CHECK: attributes [[NUW_OS_RN]] = { nounwind optsize readnone{{.*}} }
 // CHECK: attributes [[ALIGN]] = { nounwind optsize alignstack=16{{.*}} }
 // CHECK: attributes [[RT]] = { nounwind optsize returns_twice{{.*}} }
+// CHECK: attributes [[HOTPATCH]] = { nounwind optsize{{.*}}"patchable-function"="ms-hotpatch"{{.*}} }
 // CHECK: attributes [[NR]] = { noreturn optsize }
 // CHECK: attributes [[NUW_RN]] = { nounwind optsize readnone }
 // CHECK: attributes [[RT_CALL]] = { optsize returns_twice }
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1664,15 +1664,6 @@
 D->addAttr(CA);
 }
 
-static void handleNakedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (checkAttrMutualExclusion(S, D, Attr.getRange(),
- Attr.getName()))
-return;
-
-  D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context,
- Attr.getAttributeSpellingListIndex()));
-}
-
 static void handleNoReturnAttr(Sema &S, Decl *D, const AttributeList &attr) {
   if (hasDeclarator(D)) return;
 
@@ -3673,7 +3664,9 @@
 static void handleAlwaysInlineAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
   if (checkAttrMutualExclusion(S, D, Attr.getRange(),
-  Attr.getName()))
+  Attr.getName()) ||
+  checkAttrMutualExclusion(S, D, Attr.getRange(),
+   Attr.getName()))
 return;
 
   if (AlwaysInlineAttr *Inline = S.mergeAlwaysInlineAttr(
@@ -5552,7 +5545,8 @@
 handleHotAttr(S, D, Attr);
 break;
   case AttributeList::AT_Naked:
-handleNakedAttr(S, D, Attr);
+handleSimpleAttributeWithExclusions(S, D, Attr);
 break;
   case AttributeList::AT_NoReturn:
 handleNoReturnAttr(S, D, Attr);
@@ -5780,6 +5774,9 @@
 break;
   case AttributeList::AT_LayoutVersion:
 handleLayoutVersion(S, D, Attr);
+  case AttributeList::AT_MSHookPrologue:
+handleSimpleAttributeWithExclusions(S, D, Attr);
 break;
   case AttributeList::AT_MSNoVTable:
 handleSimpleAttribute(S, D, Attr);
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -1783,6 +1783,10 @@
   

[PATCH] D20449: [Basic] Change x86_64-windows-macho targets to use Windows-style va_lists.

2016-05-19 Thread Charles Davis via cfe-commits
cdavis5x created this revision.
cdavis5x added a reviewer: rsmith.
cdavis5x added a subscriber: cfe-commits.

This is a very strange target. Sema thinks it's targeting a Darwin-esque
system, while IRGen thinks it's targeting a Windows'ish system. The result
is that Clang can no longer compile `__builtin_va_arg` (either for a normal
or Win64 `va_list`) properly. So, for this target, explicitly set the
`va_list` kind to `CharPtr`, the same as Win64. This is what users expect,
anyway.

Fixes PR27663.

http://reviews.llvm.org/D20449

Files:
  lib/Basic/Targets.cpp
  test/CodeGen/windows-macho.c

Index: test/CodeGen/windows-macho.c
===
--- /dev/null
+++ test/CodeGen/windows-macho.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-windows-macho -emit-llvm -Os %s -o - \
+// RUN:| FileCheck %s
+
+// Test that, when we compile a function that uses varargs on a
+// Windows-with-Mach-O triple, we can actually compile it, and it actually
+// conforms to the Win64 ABI.
+
+// PR27663
+
+// CHECK-LABEL: i32 @va_sum
+int va_sum(unsigned int count, ...) {
+  int sum = 0;
+  __builtin_ms_va_list ap;
+
+  __builtin_ms_va_start(ap, count);
+  // CHECK: %[[AP:.*]] = alloca i8*
+  // CHECK: call void @llvm.va_start
+  while (count) {
+sum += __builtin_va_arg(ap, int);
+// CHECK: %[[AP_CUR_PRE:.*]] = load i8*, i8** %[[AP]]
+// CHECK: %[[AP_CUR:.*]] = phi i8* [ %[[AP_NEXT:.*]], {{.*}} ], [ 
%[[AP_CUR_PRE]], {{.*}} ]
+// CHECK: %[[AP_NEXT]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
+// CHECK-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
+// CHECK-NEXT: bitcast i8* %[[AP_CUR]] to i32*
+--count;
+  }
+  __builtin_ms_va_end(ap);
+  return sum;
+}
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -,6 +,39 @@
   }
 };
 
+class EFIMachOX86_64TargetInfo : public DarwinX86_64TargetInfo {
+public:
+  EFIMachOX86_64TargetInfo(const llvm::Triple &Triple,
+   const TargetOptions &Opts)
+  : DarwinX86_64TargetInfo(Triple, Opts) {}
+
+  void getTargetDefines(const LangOptions &Opts,
+MacroBuilder &Builder) const override {
+DarwinX86_64TargetInfo::getTargetDefines(Opts, Builder);
+addCygMingDefines(Opts, Builder);
+  }
+
+  BuiltinVaListKind getBuiltinVaListKind() const override {
+return TargetInfo::CharPtrBuiltinVaList;
+  }
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
+switch (CC) {
+case CC_X86StdCall:
+case CC_X86ThisCall:
+case CC_X86FastCall:
+  return CCCR_Ignore;
+case CC_C:
+case CC_X86VectorCall:
+case CC_IntelOclBicc:
+case CC_X86_64SysV:
+  return CCCR_OK;
+default:
+  return CCCR_Warning;
+}
+  }
+};
+
 class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo {
 public:
   OpenBSDX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions 
&Opts)
@@ -8362,8 +8395,11 @@
 }
 
   case llvm::Triple::x86_64:
-if (Triple.isOSDarwin() || Triple.isOSBinFormatMachO())
+if (Triple.isOSDarwin() ||
+(!Triple.isOSWindows() && Triple.isOSBinFormatMachO()))
   return new DarwinX86_64TargetInfo(Triple, Opts);
+if (Triple.isOSWindows() && Triple.isOSBinFormatMachO())
+  return new EFIMachOX86_64TargetInfo(Triple, Opts);
 
 switch (os) {
 case llvm::Triple::CloudABI:


Index: test/CodeGen/windows-macho.c
===
--- /dev/null
+++ test/CodeGen/windows-macho.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-windows-macho -emit-llvm -Os %s -o - \
+// RUN:| FileCheck %s
+
+// Test that, when we compile a function that uses varargs on a
+// Windows-with-Mach-O triple, we can actually compile it, and it actually
+// conforms to the Win64 ABI.
+
+// PR27663
+
+// CHECK-LABEL: i32 @va_sum
+int va_sum(unsigned int count, ...) {
+  int sum = 0;
+  __builtin_ms_va_list ap;
+
+  __builtin_ms_va_start(ap, count);
+  // CHECK: %[[AP:.*]] = alloca i8*
+  // CHECK: call void @llvm.va_start
+  while (count) {
+sum += __builtin_va_arg(ap, int);
+// CHECK: %[[AP_CUR_PRE:.*]] = load i8*, i8** %[[AP]]
+// CHECK: %[[AP_CUR:.*]] = phi i8* [ %[[AP_NEXT:.*]], {{.*}} ], [ %[[AP_CUR_PRE]], {{.*}} ]
+// CHECK: %[[AP_NEXT]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
+// CHECK-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
+// CHECK-NEXT: bitcast i8* %[[AP_CUR]] to i32*
+--count;
+  }
+  __builtin_ms_va_end(ap);
+  return sum;
+}
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -,6 +,39 @@
   }
 };
 
+class EFIMachOX86_64TargetInfo : public DarwinX86_64TargetInfo {
+public:
+  EFIMachOX86_64TargetInfo(const llvm::Triple &Triple,
+   cons

Re: [PATCH] D19909: [Attr] Add support for the `ms_hook_prologue` attribute.

2016-05-19 Thread Charles Davis via cfe-commits
cdavis5x updated this revision to Diff 57853.
cdavis5x marked an inline comment as done.
cdavis5x added a comment.

- Add Sema tests for the `ms_hook_prologue` attribute.
- Disallow `ms_hook_prologue` on architectures that Windows doesn't support.
- Disallow `ms_hook_prologue` with the `naked` and `always_inline` attributes.


http://reviews.llvm.org/D19909

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/function-attributes.c
  test/Sema/attr-ms-hook-prologue.c

Index: test/Sema/attr-ms-hook-prologue.c
===
--- /dev/null
+++ test/Sema/attr-ms-hook-prologue.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple i386-pc-linux -fms-extensions -fsyntax-only -verify %s
+
+int __attribute__((ms_hook_prologue)) foo(int a, int b) {
+  return a+b;
+}
+
+// expected-note@+2{{conflicting attribute is here}}
+// expected-error@+1{{'naked' and 'ms_hook_prologue' attributes are not compatible}}
+__declspec(naked) int __attribute__((ms_hook_prologue)) bar(int a, int b) {
+}
+
+// expected-note@+2{{conflicting attribute is here}}
+// expected-error@+1{{'__forceinline' and 'ms_hook_prologue' attributes are not compatible}}
+__forceinline int __attribute__((ms_hook_prologue)) baz(int a, int b) {
+  return a-b;
+}
+
+// expected-warning@+1{{'ms_hook_prologue' attribute only applies to functions}}
+int x __attribute__((ms_hook_prologue));
+
+// expected-error@+1{{'ms_hook_prologue' attribute takes no arguments}}
+int f(int a, int b) __attribute__((ms_hook_prologue(2)));
Index: test/CodeGen/function-attributes.c
===
--- test/CodeGen/function-attributes.c
+++ test/CodeGen/function-attributes.c
@@ -108,11 +108,18 @@
   _setjmp(0);
 }
 
+// CHECK-LABEL: define void @f21
+// CHECK: [[HOTPATCH:#[0-9]+]]
+// CHECK: {
+void __attribute__((ms_hook_prologue)) f21(void) {
+}
+
 // CHECK: attributes [[NUW]] = { nounwind optsize{{.*}} }
 // CHECK: attributes [[AI]] = { alwaysinline nounwind optsize{{.*}} }
 // CHECK: attributes [[NUW_OS_RN]] = { nounwind optsize readnone{{.*}} }
 // CHECK: attributes [[ALIGN]] = { nounwind optsize alignstack=16{{.*}} }
 // CHECK: attributes [[RT]] = { nounwind optsize returns_twice{{.*}} }
+// CHECK: attributes [[HOTPATCH]] = { nounwind optsize{{.*}}"patchable-function"="ms-hotpatch"{{.*}} }
 // CHECK: attributes [[NR]] = { noreturn optsize }
 // CHECK: attributes [[NUW_RN]] = { nounwind optsize readnone }
 // CHECK: attributes [[RT_CALL]] = { optsize returns_twice }
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1663,15 +1663,6 @@
 D->addAttr(CA);
 }
 
-static void handleNakedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (checkAttrMutualExclusion(S, D, Attr.getRange(),
- Attr.getName()))
-return;
-
-  D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context,
- Attr.getAttributeSpellingListIndex()));
-}
-
 static void handleNoReturnAttr(Sema &S, Decl *D, const AttributeList &attr) {
   if (hasDeclarator(D)) return;
 
@@ -3672,7 +3663,9 @@
 static void handleAlwaysInlineAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
   if (checkAttrMutualExclusion(S, D, Attr.getRange(),
-  Attr.getName()))
+  Attr.getName()) ||
+  checkAttrMutualExclusion(S, D, Attr.getRange(),
+   Attr.getName()))
 return;
 
   if (AlwaysInlineAttr *Inline = S.mergeAlwaysInlineAttr(
@@ -5525,7 +5518,8 @@
 handleHotAttr(S, D, Attr);
 break;
   case AttributeList::AT_Naked:
-handleNakedAttr(S, D, Attr);
+handleSimpleAttributeWithExclusions(S, D, Attr);
 break;
   case AttributeList::AT_NoReturn:
 handleNoReturnAttr(S, D, Attr);
@@ -5748,6 +5742,10 @@
 break;
 
   // Microsoft attributes:
+  case AttributeList::AT_MSHookPrologue:
+handleSimpleAttributeWithExclusions(S, D, Attr);
+break;
   case AttributeList::AT_MSNoVTable:
 handleSimpleAttribute(S, D, Attr);
 break;
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -1749,6 +1749,10 @@
   llvm::Function *Fn = cast(GV);
   Fn->setCallingConv(llvm::CallingConv::X86_INTR);
 }
+if (FD->hasAttr()) {
+  llvm::Function *Fn = cast(GV);
+  Fn->addFnAttr("patchable-function", "ms-hotpatch");
+}
   }
 }
 
@@ -2079,6 +2083,10 @@
 llvm::Function *Fn = cast(GV);
 Fn->setCallingConv(llvm::CallingConv::X86_INTR);
   }
+  if (FD->hasAttr()) {
+llvm::Functio

Re: [PATCH] D19909: [Attr] Add support for the `ms_hook_prologue` attribute.

2016-05-19 Thread Charles Davis via cfe-commits
cdavis5x added a comment.

For now, I've disallowed it with `naked` and `always_inline`/`__forceinline` 
attributes. Do any other attributes affect prologue generation in a way that 
might interfere with `ms_hook_prologue`? AFAICT, GCC only disallows 
`ms_hook_prologue` on a) nested functions and b) functions compiled with 
`-mfentry` (neither of which we support, AFAIK).



Comment at: include/clang/Basic/Attr.td:2032
@@ -2031,1 +2031,3 @@
 
+def MSHookPrologue : InheritableAttr {
+  let Spellings = [GCC<"ms_hook_prologue">];

aaron.ballman wrote:
> I am wondering whether we want this to be a target-specific attribute or not. 
> Right now, this attribute will be silently accepted for CPUs that MSVC does 
> not support, for instance. If we made the attribute target-specific, then 
> users would get appropriate diagnostics for those architectures.
For now, I've limited it to architectures that Windows supports.


http://reviews.llvm.org/D19909



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


Re: [PATCH] D19909: [Attr] Add support for the `ms_hook_prologue` attribute.

2016-05-16 Thread Charles Davis via cfe-commits
cdavis5x marked an inline comment as done.


Comment at: include/clang/Basic/Attr.td:2032
@@ -2031,1 +2031,3 @@
 
+def MSHookPrologue : InheritableAttr {
+  let Spellings = [GCC<"ms_hook_prologue">];

aaron.ballman wrote:
> Does this attribute appertain to all targets, or only targets that MSVC 
> supports?
Only to //CPUs// that MSVC supports, but it works on all OSes--even non-Windows 
ones.

I should mention that this attribute was specifically added to GCC so Wine 
could use it.


http://reviews.llvm.org/D19909



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


Re: [PATCH] D19909: [Attr] Add support for the `ms_hook_prologue` attribute.

2016-05-16 Thread Charles Davis via cfe-commits
cdavis5x updated this revision to Diff 57389.
cdavis5x added a comment.

- Use Sanjoy's `patchable-function` attribute.
- Add documentation for this new attribute.


http://reviews.llvm.org/D19909

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/function-attributes.c

Index: test/CodeGen/function-attributes.c
===
--- test/CodeGen/function-attributes.c
+++ test/CodeGen/function-attributes.c
@@ -108,11 +108,18 @@
   _setjmp(0);
 }
 
+// CHECK-LABEL: define void @f21
+// CHECK: [[HOTPATCH:#[0-9]+]]
+// CHECK: {
+void __attribute__((ms_hook_prologue)) f21(void) {
+}
+
 // CHECK: attributes [[NUW]] = { nounwind optsize{{.*}} }
 // CHECK: attributes [[AI]] = { alwaysinline nounwind optsize{{.*}} }
 // CHECK: attributes [[NUW_OS_RN]] = { nounwind optsize readnone{{.*}} }
 // CHECK: attributes [[ALIGN]] = { nounwind optsize alignstack=16{{.*}} }
 // CHECK: attributes [[RT]] = { nounwind optsize returns_twice{{.*}} }
+// CHECK: attributes [[HOTPATCH]] = { nounwind optsize{{.*}}"patchable-function"="ms-hotpatch"{{.*}} }
 // CHECK: attributes [[NR]] = { noreturn optsize }
 // CHECK: attributes [[NUW_RN]] = { nounwind optsize readnone }
 // CHECK: attributes [[RT_CALL]] = { optsize returns_twice }
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5748,6 +5748,9 @@
 break;
 
   // Microsoft attributes:
+  case AttributeList::AT_MSHookPrologue:
+handleSimpleAttribute(S, D, Attr);
+break;
   case AttributeList::AT_MSNoVTable:
 handleSimpleAttribute(S, D, Attr);
 break;
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -1749,6 +1749,10 @@
   llvm::Function *Fn = cast(GV);
   Fn->setCallingConv(llvm::CallingConv::X86_INTR);
 }
+if (FD->hasAttr()) {
+  llvm::Function *Fn = cast(GV);
+  Fn->addFnAttr("patchable-function", "ms-hotpatch");
+}
   }
 }
 
@@ -2079,6 +2083,10 @@
 llvm::Function *Fn = cast(GV);
 Fn->setCallingConv(llvm::CallingConv::X86_INTR);
   }
+  if (FD->hasAttr()) {
+llvm::Function *Fn = cast(GV);
+Fn->addFnAttr("patchable-function", "ms-hotpatch");
+  }
 }
   }
 };
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -494,6 +494,19 @@
   }];
 }
 
+def MSHookPrologueDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``ms_hook_prologue`` attribute marks a function as "hotpatchable" according
+to conventions used on Windows. Specifically, enough space will be ensured
+in the prologue for a short jump, and an architecturally dependently sized
+patch space will be reserved prior to the entry point. See the documentation
+for the `/HOTPATCH`_ switch on MSDN.
+
+.. _`/HOTPATCH/: https://msdn.microsoft.com/en-us/library/ms173507.aspx
+  }];
+}
+
 def NoDebugDocs : Documentation {
   let Category = DocCatVariable;
   let Content = [{
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -2029,6 +2029,12 @@
 
 // Microsoft-related attributes
 
+def MSHookPrologue : InheritableAttr {
+  let Spellings = [GCC<"ms_hook_prologue">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [MSHookPrologueDocs];
+}
+
 def MSNoVTable : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"novtable">];
   let Subjects = SubjectList<[CXXRecord]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19909: [Attr] Add support for the `ms_hook_prologue` attribute.

2016-05-04 Thread Charles Davis via cfe-commits
cdavis5x created this revision.
cdavis5x added reviewers: aaron.ballman, rnk.
cdavis5x added a subscriber: cfe-commits.
cdavis5x added a dependency: D19908: [X86] Support the "ms-hotpatch" attribute..

Based on a patch by Michael Mueller.

This attribute specifies that a function can be hooked or patched. This
mechanism was originally devised by Microsoft for hotpatching their
binaries (which they're constantly updating to stay ahead of crackers,
script kiddies, and other ne'er-do-wells on the Internet), but it's now
commonly abused by Windows programs that want to hook API functions. It
is for this reason that this attribute was added to GCC--hence the name,
`ms_hook_prologue`.

Depends on D19908.

http://reviews.llvm.org/D19909

Files:
  include/clang/Basic/Attr.td
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/function-attributes.c

Index: test/CodeGen/function-attributes.c
===
--- test/CodeGen/function-attributes.c
+++ test/CodeGen/function-attributes.c
@@ -108,11 +108,18 @@
   _setjmp(0);
 }
 
+// CHECK-LABEL: define void @f21
+// CHECK: [[HOTPATCH:#[0-9]+]]
+// CHECK: {
+void __attribute__((ms_hook_prologue)) f21(void) {
+}
+
 // CHECK: attributes [[NUW]] = { nounwind optsize{{.*}} }
 // CHECK: attributes [[AI]] = { alwaysinline nounwind optsize{{.*}} }
 // CHECK: attributes [[NUW_OS_RN]] = { nounwind optsize readnone{{.*}} }
 // CHECK: attributes [[ALIGN]] = { nounwind optsize alignstack=16{{.*}} }
 // CHECK: attributes [[RT]] = { nounwind optsize returns_twice{{.*}} }
+// CHECK: attributes [[HOTPATCH]] = { nounwind 
optsize{{.*}}"ms-hotpatch"{{.*}} }
 // CHECK: attributes [[NR]] = { noreturn optsize }
 // CHECK: attributes [[NUW_RN]] = { nounwind optsize readnone }
 // CHECK: attributes [[RT_CALL]] = { optsize returns_twice }
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5742,6 +5742,9 @@
 break;
 
   // Microsoft attributes:
+  case AttributeList::AT_MSHookPrologue:
+handleSimpleAttribute(S, D, Attr);
+break;
   case AttributeList::AT_MSNoVTable:
 handleSimpleAttribute(S, D, Attr);
 break;
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -1743,6 +1743,10 @@
   llvm::Function *Fn = cast(GV);
   Fn->setCallingConv(llvm::CallingConv::X86_INTR);
 }
+if (FD->hasAttr()) {
+  llvm::Function *Fn = cast(GV);
+  Fn->addFnAttr("ms-hotpatch");
+}
   }
 }
 
@@ -2073,6 +2077,10 @@
 llvm::Function *Fn = cast(GV);
 Fn->setCallingConv(llvm::CallingConv::X86_INTR);
   }
+  if (FD->hasAttr()) {
+llvm::Function *Fn = cast(GV);
+Fn->addFnAttr("ms-hotpatch");
+  }
 }
   }
 };
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -2029,6 +2029,12 @@
 
 // Microsoft-related attributes
 
+def MSHookPrologue : InheritableAttr {
+  let Spellings = [GCC<"ms_hook_prologue">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];
+}
+
 def MSNoVTable : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"novtable">];
   let Subjects = SubjectList<[CXXRecord]>;


Index: test/CodeGen/function-attributes.c
===
--- test/CodeGen/function-attributes.c
+++ test/CodeGen/function-attributes.c
@@ -108,11 +108,18 @@
   _setjmp(0);
 }
 
+// CHECK-LABEL: define void @f21
+// CHECK: [[HOTPATCH:#[0-9]+]]
+// CHECK: {
+void __attribute__((ms_hook_prologue)) f21(void) {
+}
+
 // CHECK: attributes [[NUW]] = { nounwind optsize{{.*}} }
 // CHECK: attributes [[AI]] = { alwaysinline nounwind optsize{{.*}} }
 // CHECK: attributes [[NUW_OS_RN]] = { nounwind optsize readnone{{.*}} }
 // CHECK: attributes [[ALIGN]] = { nounwind optsize alignstack=16{{.*}} }
 // CHECK: attributes [[RT]] = { nounwind optsize returns_twice{{.*}} }
+// CHECK: attributes [[HOTPATCH]] = { nounwind optsize{{.*}}"ms-hotpatch"{{.*}} }
 // CHECK: attributes [[NR]] = { noreturn optsize }
 // CHECK: attributes [[NUW_RN]] = { nounwind optsize readnone }
 // CHECK: attributes [[RT_CALL]] = { optsize returns_twice }
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5742,6 +5742,9 @@
 break;
 
   // Microsoft attributes:
+  case AttributeList::AT_MSHookPrologue:
+handleSimpleAttribute(S, D, Attr);
+break;
   case AttributeList::AT_MSNoVTable:
 handleSimpleAttribute(S, D, Attr);
 break;
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++

r247941 - Support __builtin_ms_va_list.

2015-09-17 Thread Charles Davis via cfe-commits
Author: cdavis
Date: Thu Sep 17 15:55:33 2015
New Revision: 247941

URL: http://llvm.org/viewvc/llvm-project?rev=247941&view=rev
Log:
Support __builtin_ms_va_list.

Summary:
This change adds support for `__builtin_ms_va_list`, a GCC extension for
variadic `ms_abi` functions. The existing `__builtin_va_list` support is
inadequate for this because `va_list` is defined differently in the Win64
ABI vs. the System V/AMD64 ABI.

Depends on D1622.

Reviewers: rsmith, rnk, rjmccall

CC: cfe-commits

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

Added:
cfe/trunk/test/Sema/varargs-win64.c
cfe/trunk/test/Sema/varargs-x86-32.c
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTDiagnostic.cpp
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/ABIInfo.h
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/CodeGen/ms_abi.c
cfe/trunk/test/PCH/Inputs/va_arg.h
cfe/trunk/test/PCH/va_arg.c
cfe/trunk/test/PCH/va_arg.cpp
cfe/trunk/test/PCH/va_arg.h
cfe/trunk/test/Sema/varargs-x86-64.c
cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=247941&r1=247940&r2=247941&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Sep 17 15:55:33 2015
@@ -216,6 +216,9 @@ class ASTContext : public RefCountedBase
   /// __builtin_va_list type.
   mutable TypedefDecl *BuiltinVaListDecl;
 
+  /// The typedef for the predefined \c __builtin_ms_va_list type.
+  mutable TypedefDecl *BuiltinMSVaListDecl;
+
   /// \brief The typedef for the predefined \c id type.
   mutable TypedefDecl *ObjCIdDecl;
   
@@ -1579,6 +1582,15 @@ public:
   /// for some targets.
   Decl *getVaListTagDecl() const;
 
+  /// Retrieve the C type declaration corresponding to the predefined
+  /// \c __builtin_ms_va_list type.
+  TypedefDecl *getBuiltinMSVaListDecl() const;
+
+  /// Retrieve the type of the \c __builtin_ms_va_list type.
+  QualType getBuiltinMSVaListType() const {
+return getTypeDeclType(getBuiltinMSVaListDecl());
+  }
+
   /// \brief Return a type with additional \c const, \c volatile, or
   /// \c restrict qualifiers.
   QualType getCVRQualifiedType(QualType T, unsigned CVR) const {

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=247941&r1=247940&r2=247941&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Sep 17 15:55:33 2015
@@ -3699,33 +3699,35 @@ public:
   }
 };
 
-/// VAArgExpr, used for the builtin function __builtin_va_arg.
+/// Represents a call to the builtin function \c __builtin_va_arg.
 class VAArgExpr : public Expr {
   Stmt *Val;
-  TypeSourceInfo *TInfo;
+  llvm::PointerIntPair TInfo;
   SourceLocation BuiltinLoc, RParenLoc;
 public:
-  VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo,
-SourceLocation RPLoc, QualType t)
-: Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary,
-   t->isDependentType(), false,
-   (TInfo->getType()->isInstantiationDependentType() ||
-e->isInstantiationDependent()),
-   (TInfo->getType()->containsUnexpandedParameterPack() ||
-e->containsUnexpandedParameterPack())),
-  Val(e), TInfo(TInfo),
-  BuiltinLoc(BLoc),
-  RParenLoc(RPLoc) { }
+  VAArgExpr(SourceLocation BLoc, Expr *e, TypeSourceInfo *TInfo,
+SourceLocation RPLoc, QualType t, bool IsMS)
+  : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, t->isDependentType(),
+ false, (TInfo->getType()->isInstantiationDependentType() ||
+ e->isInstantiationDependent()),
+ (TInfo->getType()->containsUnexpandedParameterPack() |

Re: [PATCH] D1623: Support __builtin_ms_va_list.

2015-09-17 Thread Charles Davis via cfe-commits
cdavis5x added a comment.

Ping...


http://reviews.llvm.org/D1623



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


Re: [PATCH] D1623: Support __builtin_ms_va_list.

2015-09-14 Thread Charles Davis via cfe-commits
cdavis5x added inline comments.


Comment at: lib/CodeGen/CGCall.cpp:3598
@@ -3599,1 +3597,3 @@
+Address CodeGenFunction::EmitVAArg(Address VAListAddr, QualType Ty, bool IsMS) 
{
+  return CGM.getTypes().getABIInfo().EmitVAArg(*this, VAListAddr, Ty, IsMS);
 }

rjmccall wrote:
> rnk wrote:
> > I think keeping the va_arg logic in TargetInfo.cpp is good, but we don't 
> > need to thread IsMS through every EmitVAArg override. Instead, we can do 
> > something like this here:
> >   if (IsMS)
> > return CGM.getTypes().getABIInfo().EmitMSVAArg(*this, VAListAddr, Ty);
> >   return CGM.getTypes().getABIInfo().EmitVAArg(*this, VAListAddr, Ty);
> I agree, especially because TargetInfo.cpp is partially maintained by backend 
> authors; let's not force them all to know about this weird extension.
Done.


Comment at: lib/CodeGen/CGExprAgg.cpp:966
@@ -965,1 +965,3 @@
+ : CGF.EmitVAListRef(VE->getSubExpr());
+  Address ArgPtr = CGF.EmitVAArg(ArgValue, VE->getType(), 
VE->isMicrosoftABI());
 

rjmccall wrote:
> We have exactly this same pattern of code in three different places, and it's 
> kindof begging for somebody to add another emitter that's missing the MS ABI 
> site.  Maybe instead of having EmitVAListRef as a separate function, we 
> should just have this:
>   Address CGF::EmitVAArgExpr(VAArgExpr *E)
> and it can check the ABI and do the right combination of things.
Done. 

I kept `EmitVAListRef` because it's used elsewhere. Also, I had to add an out 
parameter to `EmitVAArg` for the `va_list` reference, because some callers 
(like this one!) do something with it if `EmitVAArg` fails.


Comment at: lib/Sema/SemaExpr.cpp:11664-11672
@@ -11662,1 +11663,11 @@
+
+  // It might be a __builtin_ms_va_list.
+  if (!E->isTypeDependent() && Context.getTargetInfo().hasBuiltinMSVaList()) {
+QualType MSVaListType = Context.getBuiltinMSVaListType();
+if (Context.hasSameType(MSVaListType, E->getType())) {
+  if (CheckForModifiableLvalue(E, BuiltinLoc, *this))
+return ExprError();
+  IsMS = true;
+}
+  }
 

rsmith wrote:
> If `__builtin_va_list` and `__builtin_ms_va_list` are the same type, this 
> will set `IsMS` to true, which is not wrong per se but seems a bit 
> surprising. (`IsMS` is the "I'm using an unnatural ABI" flag, and I think 
> it'd be a bit better to not set it for normal `va_start` / `va_arg` / 
> `va_end`, even when targeting the MS ABI. Thoughts?
I agree. Fixed.


http://reviews.llvm.org/D1623



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


Re: [PATCH] D1623: Support __builtin_ms_va_list.

2015-09-14 Thread Charles Davis via cfe-commits
cdavis5x updated this revision to Diff 34728.
cdavis5x added a comment.

Address review comments.

- Pull out `va_arg` emission on `__builtin_ms_va_arg` to its own method on 
`ABIInfo`. That way, ABI implementers don't need to care that this extension 
even exists.
- Attempt to push repeated `va_arg` emission code in 
CGExpr{Scalar,Agg,Complex}.cpp down into `CodeGenFunction::EmitVAArg`.
- Don't ever consider a `VAArgExpr` to be a Microsoft one when the native 
`va_list` happens to be the same as the MS one.

Also:

- Rebase onto http://reviews.llvm.org/rL247603.
- Add a test that we lower `va_arg()` and `va_copy()` correctly even with a 
Win64 `va_list` inside a System V function.


http://reviews.llvm.org/D1623

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Expr.h
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTDiagnostic.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/ABIInfo.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/CodeGen/ms_abi.c
  test/PCH/Inputs/va_arg.h
  test/PCH/va_arg.c
  test/PCH/va_arg.cpp
  test/PCH/va_arg.h
  test/Sema/varargs-win64.c
  test/Sema/varargs-x86-32.c
  test/Sema/varargs-x86-64.c
  test/SemaTemplate/instantiate-expr-3.cpp

Index: test/SemaTemplate/instantiate-expr-3.cpp
===
--- test/SemaTemplate/instantiate-expr-3.cpp
+++ test/SemaTemplate/instantiate-expr-3.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
 
 // -
 // Imaginary literals
@@ -108,12 +108,41 @@
 struct VaArg1 {
   void f(int n, ...) {
 VaList va;
-__builtin_va_start(va, n); // expected-error{{int}}
+__builtin_va_start(va, n); // expected-error{{int}} expected-error{{char *}}
 for (int i = 0; i != n; ++i)
   (void)__builtin_va_arg(va, ArgType); // expected-error{{int}}
-__builtin_va_end(va); // expected-error{{int}}
+__builtin_va_end(va); // expected-error{{int}} expected-error{{char *}}
   }
 };
 
 template struct VaArg1<__builtin_va_list, int>;
+template struct VaArg1<__builtin_ms_va_list, int>; // expected-note{{instantiation}}
 template struct VaArg1; // expected-note{{instantiation}}
+
+template
+struct VaArg2 {
+  void __attribute__((ms_abi)) f(int n, ...) {
+__builtin_ms_va_list va;
+__builtin_ms_va_start(va, n);
+for (int i = 0; i != n; ++i)
+  (void)__builtin_va_arg(va, ArgType);
+__builtin_ms_va_end(va);
+  }
+};
+
+template struct VaArg2;
+
+template
+struct VaArg3 {
+  void __attribute__((ms_abi)) f(int n, ...) {
+VaList va;
+__builtin_ms_va_start(va, n); // expected-error{{int}} expected-error{{__va_list_tag}}
+for (int i = 0; i != n; ++i)
+  (void)__builtin_va_arg(va, ArgType); // expected-error{{int}}
+__builtin_ms_va_end(va); // expected-error{{int}} expected-error{{__va_list_tag}}
+  }
+};
+
+template struct VaArg3<__builtin_ms_va_list, int>;
+template struct VaArg3<__builtin_va_list, int>; // expected-note{{instantiation}}
+template struct VaArg3; // expected-note{{instantiation}}
Index: test/Sema/varargs-x86-64.c
===
--- test/Sema/varargs-x86-64.c
+++ test/Sema/varargs-x86-64.c
@@ -6,3 +6,75 @@
   (void)__builtin_va_arg(args2, int); // expected-error {{first argument to 'va_arg' is of type 'const __builtin_va_list' and not 'va_list'}}
 }
 
+void f2(int a, ...) {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a); // expected-error {{'__builtin_ms_va_start' used in System V ABI function}}
+}
+
+void __attribute__((ms_abi)) g1(int a) {
+  __builtin_ms_va_list ap;
+
+  __builtin_ms_va_start(ap, a, a); // expected-error {{too many arguments to function}}
+  __builtin_ms_va_start(ap, a); // expected-error {{'va_start' used in function with fixed args}}
+}
+
+void __attribute__((ms_abi)) g2(int a, int b, ...) {
+  __builtin_ms_va_list ap;
+
+  __builtin_ms_va_start(ap, 10); // expected-warning {{second parameter of 'va_start' not last named argument}}
+  __builtin_ms_va_start(ap, a); // expected-warning {{second parameter of 'va_start' not last named argument}}
+  __builtin_ms_va_start(ap, b);
+}
+
+void __attribute__((ms_abi)) g3(float a, ...) {
+  __builtin_ms_va_list ap;
+
+  __builtin_ms_va_start(ap, a);
+  __builti

Re: [PATCH] D1623: Support __builtin_ms_va_list.

2015-09-10 Thread Charles Davis via cfe-commits
cdavis5x updated this revision to Diff 34415.
cdavis5x added a comment.

- Rebase onto http://reviews.llvm.org/rL247238.
- Run `clang-format` on this patch.
- Push `va_arg` emission down into the `ABIInfo` hierarchy.

I threaded the `IsMS` parameter from the `VAArgExpr` through the
`EmitVAArg` methods. I'm not entirely happy about this design; I'm open
to suggestions. One thing this does help, though, is supporting this
on other architectures (ARM, maybe?).


http://reviews.llvm.org/D1623

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Expr.h
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTDiagnostic.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/ABIInfo.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/CodeGen/ms_abi.c
  test/PCH/Inputs/va_arg.h
  test/PCH/va_arg.c
  test/PCH/va_arg.cpp
  test/PCH/va_arg.h
  test/Sema/varargs-win64.c
  test/Sema/varargs-x86-32.c
  test/Sema/varargs-x86-64.c
  test/SemaTemplate/instantiate-expr-3.cpp

Index: test/SemaTemplate/instantiate-expr-3.cpp
===
--- test/SemaTemplate/instantiate-expr-3.cpp
+++ test/SemaTemplate/instantiate-expr-3.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
 
 // -
 // Imaginary literals
@@ -108,12 +108,41 @@
 struct VaArg1 {
   void f(int n, ...) {
 VaList va;
-__builtin_va_start(va, n); // expected-error{{int}}
+__builtin_va_start(va, n); // expected-error{{int}} expected-error{{char *}}
 for (int i = 0; i != n; ++i)
   (void)__builtin_va_arg(va, ArgType); // expected-error{{int}}
-__builtin_va_end(va); // expected-error{{int}}
+__builtin_va_end(va);  // expected-error{{int}} expected-error{{char *}}
   }
 };
 
 template struct VaArg1<__builtin_va_list, int>;
+template struct VaArg1<__builtin_ms_va_list, int>; // expected-note{{instantiation}}
 template struct VaArg1; // expected-note{{instantiation}}
+
+template 
+struct VaArg2 {
+  void __attribute__((ms_abi)) f(int n, ...) {
+__builtin_ms_va_list va;
+__builtin_ms_va_start(va, n);
+for (int i = 0; i != n; ++i)
+  (void)__builtin_va_arg(va, ArgType);
+__builtin_ms_va_end(va);
+  }
+};
+
+template struct VaArg2;
+
+template 
+struct VaArg3 {
+  void __attribute__((ms_abi)) f(int n, ...) {
+VaList va;
+__builtin_ms_va_start(va, n); // expected-error{{int}} expected-error{{__va_list_tag}}
+for (int i = 0; i != n; ++i)
+  (void)__builtin_va_arg(va, ArgType); // expected-error{{int}}
+__builtin_ms_va_end(va);   // expected-error{{int}} expected-error{{__va_list_tag}}
+  }
+};
+
+template struct VaArg3<__builtin_ms_va_list, int>;
+template struct VaArg3<__builtin_va_list, int>; // expected-note{{instantiation}}
+template struct VaArg3;   // expected-note{{instantiation}}
Index: test/Sema/varargs-x86-64.c
===
--- test/Sema/varargs-x86-64.c
+++ test/Sema/varargs-x86-64.c
@@ -6,3 +6,77 @@
   (void)__builtin_va_arg(args2, int); // expected-error {{first argument to 'va_arg' is of type 'const __builtin_va_list' and not 'va_list'}}
 }
 
+void f2(int a, ...) {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a); // expected-error {{'__builtin_ms_va_start' used in System V ABI function}}
+}
+
+void __attribute__((ms_abi)) g1(int a) {
+  __builtin_ms_va_list ap;
+
+  __builtin_ms_va_start(ap, a, a); // expected-error {{too many arguments to function}}
+  __builtin_ms_va_start(ap, a);// expected-error {{'va_start' used in function with fixed args}}
+}
+
+void __attribute__((ms_abi)) g2(int a, int b, ...) {
+  __builtin_ms_va_list ap;
+
+  __builtin_ms_va_start(ap, 10); // expected-warning {{second parameter of 'va_start' not last named argument}}
+  __builtin_ms_va_start(ap, a);  // expected-warning {{second parameter of 'va_start' not last named argument}}
+  __builtin_ms_va_start(ap, b);
+}
+
+void __attribute__((ms_abi)) g3(float a, ...) {
+  __builtin_ms_va_list ap;
+
+  __builtin_ms_va_start(ap, a);
+  __builtin_ms_va_start(ap, (a));
+}
+
+void __attribute__((ms_abi)) g5() {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, ap); // expected-error {{'va_start' used in function wi

Re: [PATCH] D1623: Support __builtin_ms_va_list.

2015-09-03 Thread Charles Davis via cfe-commits
cdavis5x added inline comments.


Comment at: include/clang/AST/Expr.h:3709
@@ -3708,3 +3708,3 @@
   VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo,
-SourceLocation RPLoc, QualType t)
+SourceLocation RPLoc, QualType t, bool IsMS = false)
 : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary,

rsmith wrote:
> Is there a reason to add a default argument for this? It looks like all calls 
> provide an argument.
Nope. The default arg is gone now.


Comment at: include/clang/AST/Expr.h:3720-3722
@@ -3719,4 +3719,5 @@
 
-  /// \brief Create an empty __builtin_va_arg expression.
-  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
+  /// Create an empty __builtin_va_arg expression.
+  explicit VAArgExpr(EmptyShell Empty, bool IsMS = false)
+: Expr(VAArgExprClass, Empty), Val(0), TInfo(0, IsMS) { }
 

rsmith wrote:
> The `IsMS` flag you added here is never used.
Removed. (I don't know what I was thinking with that...)


Comment at: lib/Sema/SemaChecking.cpp:1038-1040
@@ -1037,1 +1037,5 @@
+  case X86::BI__builtin_ms_va_start:
+if (Context.getTargetInfo().getTriple().getArch() != llvm::Triple::x86_64)
+  return false;
+return SemaBuiltinVAStart(TheCall);
   case X86::BI_mm_prefetch: i = 1; l = 0; u = 3; break;

rsmith wrote:
> Can we do better than this? I think it'd be better to check that 
> `__builtin_ms_va_start` only occurs in a function using the MS ABI's variadic 
> calling convention, and `__builtin_va_start` only occurs in a function using 
> the normal variadic C calling convention.
Done.


http://reviews.llvm.org/D1623



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


Re: [PATCH] D1623: Support __builtin_ms_va_list.

2015-09-03 Thread Charles Davis via cfe-commits
cdavis5x updated this revision to Diff 34012.
cdavis5x added a comment.

Address @rsmith's comments.


http://reviews.llvm.org/D1623

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Expr.h
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTDiagnostic.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/CodeGen/ms_abi.c
  test/PCH/Inputs/va_arg.h
  test/PCH/va_arg.c
  test/PCH/va_arg.cpp
  test/PCH/va_arg.h
  test/Sema/varargs-win64.c
  test/Sema/varargs-x86-32.c
  test/Sema/varargs-x86-64.c
  test/SemaTemplate/instantiate-expr-3.cpp

Index: test/SemaTemplate/instantiate-expr-3.cpp
===
--- test/SemaTemplate/instantiate-expr-3.cpp
+++ test/SemaTemplate/instantiate-expr-3.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
 
 // -
 // Imaginary literals
@@ -108,12 +108,41 @@
 struct VaArg1 {
   void f(int n, ...) {
 VaList va;
-__builtin_va_start(va, n); // expected-error{{int}}
+__builtin_va_start(va, n); // expected-error{{int}} expected-error{{char *}}
 for (int i = 0; i != n; ++i)
   (void)__builtin_va_arg(va, ArgType); // expected-error{{int}}
-__builtin_va_end(va); // expected-error{{int}}
+__builtin_va_end(va); // expected-error{{int}} expected-error{{char *}}
   }
 };
 
 template struct VaArg1<__builtin_va_list, int>;
+template struct VaArg1<__builtin_ms_va_list, int>; // expected-note{{instantiation}}
 template struct VaArg1; // expected-note{{instantiation}}
+
+template
+struct VaArg2 {
+  void __attribute__((ms_abi)) f(int n, ...) {
+__builtin_ms_va_list va;
+__builtin_ms_va_start(va, n);
+for (int i = 0; i != n; ++i)
+  (void)__builtin_va_arg(va, ArgType);
+__builtin_ms_va_end(va);
+  }
+};
+
+template struct VaArg2;
+
+template
+struct VaArg3 {
+  void __attribute__((ms_abi)) f(int n, ...) {
+VaList va;
+__builtin_ms_va_start(va, n); // expected-error{{int}} expected-error{{__va_list_tag}}
+for (int i = 0; i != n; ++i)
+  (void)__builtin_va_arg(va, ArgType); // expected-error{{int}}
+__builtin_ms_va_end(va); // expected-error{{int}} expected-error{{__va_list_tag}}
+  }
+};
+
+template struct VaArg3<__builtin_ms_va_list, int>;
+template struct VaArg3<__builtin_va_list, int>; // expected-note{{instantiation}}
+template struct VaArg3; // expected-note{{instantiation}}
Index: test/Sema/varargs-x86-64.c
===
--- test/Sema/varargs-x86-64.c
+++ test/Sema/varargs-x86-64.c
@@ -6,3 +6,80 @@
   (void)__builtin_va_arg(args2, int); // expected-error {{first argument to 'va_arg' is of type 'const __builtin_va_list' and not 'va_list'}}
 }
 
+void f2(int a, ...) {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a); // expected-error {{'__builtin_ms_va_start' used in System V ABI function}}
+}
+
+void __attribute__((ms_abi)) g1(int a)
+{
+__builtin_ms_va_list ap;
+
+__builtin_ms_va_start(ap, a, a); // expected-error {{too many arguments to function}}
+__builtin_ms_va_start(ap, a); // expected-error {{'va_start' used in function with fixed args}}
+}
+
+void __attribute__((ms_abi)) g2(int a, int b, ...)
+{
+__builtin_ms_va_list ap;
+
+__builtin_ms_va_start(ap, 10); // expected-warning {{second parameter of 'va_start' not last named argument}}
+__builtin_ms_va_start(ap, a); // expected-warning {{second parameter of 'va_start' not last named argument}}
+__builtin_ms_va_start(ap, b);
+}
+
+void __attribute__((ms_abi)) g3(float a, ...)
+{
+__builtin_ms_va_list ap;
+
+__builtin_ms_va_start(ap, a);
+__builtin_ms_va_start(ap, (a));
+}
+
+void __attribute__((ms_abi)) g5() {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap,ap); // expected-error {{'va_start' used in function with fixed args}}
+}
+
+void __attribute__((ms_abi)) g6(int a, ...) {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap); // expected-error {{too few arguments to function}}
+}
+
+void __attribute__((ms_abi))
+bar(__builtin_ms_va_list authors, ...) {
+  __builtin_ms_va_start (authors, authors);
+  (void)__builtin_va_arg(authors, int);
+  __builtin_ms_va_end (authors);
+}
+
+void __attribute__((ms_abi)) g7(i

Re: [PATCH] D1623: Support __builtin_ms_va_list.

2015-08-28 Thread Charles Davis via cfe-commits
cdavis5x updated this revision to Diff 33490.
cdavis5x added a comment.

- Rebase onto http://reviews.llvm.org/rL246348.
- Register the `__builtin_ms_va_list` predef decl. Fixes a nasty interaction 
with modules.
- Mark `__builtin_ms_va_start` builtin as manually type-checked.


http://reviews.llvm.org/D1623

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Expr.h
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/TargetInfo.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTDiagnostic.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/CodeGen/ms_abi.c
  test/PCH/Inputs/va_arg.h
  test/PCH/va_arg.c
  test/PCH/va_arg.cpp
  test/PCH/va_arg.h
  test/Sema/varargs-x86-64.c
  test/SemaTemplate/instantiate-expr-3.cpp

Index: test/SemaTemplate/instantiate-expr-3.cpp
===
--- test/SemaTemplate/instantiate-expr-3.cpp
+++ test/SemaTemplate/instantiate-expr-3.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
 
 // -
 // Imaginary literals
@@ -108,12 +108,41 @@
 struct VaArg1 {
   void f(int n, ...) {
 VaList va;
-__builtin_va_start(va, n); // expected-error{{int}}
+__builtin_va_start(va, n); // expected-error{{int}} expected-error{{char *}}
 for (int i = 0; i != n; ++i)
   (void)__builtin_va_arg(va, ArgType); // expected-error{{int}}
-__builtin_va_end(va); // expected-error{{int}}
+__builtin_va_end(va); // expected-error{{int}} expected-error{{char *}}
   }
 };
 
 template struct VaArg1<__builtin_va_list, int>;
+template struct VaArg1<__builtin_ms_va_list, int>; // expected-note{{instantiation}}
 template struct VaArg1; // expected-note{{instantiation}}
+
+template
+struct VaArg2 {
+  void f(int n, ...) {
+__builtin_ms_va_list va;
+__builtin_ms_va_start(va, n);
+for (int i = 0; i != n; ++i)
+  (void)__builtin_va_arg(va, ArgType);
+__builtin_ms_va_end(va);
+  }
+};
+
+template struct VaArg2;
+
+template
+struct VaArg3 {
+  void f(int n, ...) {
+VaList va;
+__builtin_ms_va_start(va, n); // expected-error{{int}} expected-error{{__va_list_tag}}
+for (int i = 0; i != n; ++i)
+  (void)__builtin_va_arg(va, ArgType); // expected-error{{int}}
+__builtin_ms_va_end(va); // expected-error{{int}} expected-error{{__va_list_tag}}
+  }
+};
+
+template struct VaArg3<__builtin_ms_va_list, int>;
+template struct VaArg3<__builtin_va_list, int>; // expected-note{{instantiation}}
+template struct VaArg3; // expected-note{{instantiation}}
Index: test/Sema/varargs-x86-64.c
===
--- test/Sema/varargs-x86-64.c
+++ test/Sema/varargs-x86-64.c
@@ -6,3 +6,70 @@
   (void)__builtin_va_arg(args2, int); // expected-error {{first argument to 'va_arg' is of type 'const __builtin_va_list' and not 'va_list'}}
 }
 
+void __attribute__((ms_abi)) g1(int a)
+{
+__builtin_ms_va_list ap;
+
+__builtin_ms_va_start(ap, a, a); // expected-error {{too many arguments to function}}
+__builtin_ms_va_start(ap, a); // expected-error {{'va_start' used in function with fixed args}}
+}
+
+void __attribute__((ms_abi)) g2(int a, int b, ...)
+{
+__builtin_ms_va_list ap;
+
+__builtin_ms_va_start(ap, 10); // expected-warning {{second parameter of 'va_start' not last named argument}}
+__builtin_ms_va_start(ap, a); // expected-warning {{second parameter of 'va_start' not last named argument}}
+__builtin_ms_va_start(ap, b);
+}
+
+void __attribute__((ms_abi)) g3(float a, ...)
+{
+__builtin_ms_va_list ap;
+
+__builtin_ms_va_start(ap, a);
+__builtin_ms_va_start(ap, (a));
+}
+
+void __attribute__((ms_abi)) g5() {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap,ap); // expected-error {{'va_start' used in function with fixed args}}
+}
+
+void __attribute__((ms_abi)) g6(int a, ...) {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap); // expected-error {{too few arguments to function}}
+}
+
+void __attribute__((ms_abi))
+bar(__builtin_ms_va_list authors, ...) {
+  __builtin_ms_va_start (authors, authors);
+  (void)__builtin_va_arg(authors, int);
+  __builtin_ms_va_end (authors);
+}
+
+void __attribute__((ms_abi)) g7(int a, ...) {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a);
+  // FIXME: This error message is sub-par.
+  __builtin_va_arg(ap, int) = 1; // expected-er