Re: [PATCH] D23728: [Clang-tidy] Fix style in some checks documentation

2016-08-22 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279494: Fix style in some Clang-tidy checks documentation. 
(authored by eugenezelenko).

Changed prior to commit:
  https://reviews.llvm.org/D23728?vs=68933=68941#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23728

Files:
  
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/google-global-names-in-headers.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-argument-comment.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-misplaced-widening-cast.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-missing-comma.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-braces-around-statements.rst

Index: clang-tools-extra/trunk/docs/clang-tidy/checks/google-global-names-in-headers.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/google-global-names-in-headers.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/google-global-names-in-headers.rst
@@ -3,15 +3,18 @@
 google-global-names-in-headers
 ==
 
-Flag global namespace pollution in header files.
-Right now it only triggers on ``using`` declarations and directives.
-
-The check supports these options:
-  - `HeaderFileExtensions`: a comma-separated list of filename extensions
-of header files (the filename extensions should not contain "." prefix).
-"h" by default.
-For extension-less header files, using an empty string or leaving an
-empty string between "," if there are other filename extensions.
+Flag global namespace pollution in header files. Right now it only triggers on
+``using`` declarations and directives.
 
 The relevant style guide section is
 https://google.github.io/styleguide/cppguide.html#Namespaces.
+
+Options
+---
+
+.. option:: HeaderFileExtensions
+
+   A comma-separated list of filename extensions of header files (the filename
+   extensions should not contain "." prefix). "h" by default. For extension-less
+   header files, using an empty string or leaving an empty string between ","
+   if there are other filename extensions.
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-misplaced-widening-cast.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-misplaced-widening-cast.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-misplaced-widening-cast.rst
@@ -8,21 +8,25 @@
 is misplaced, and there can be loss of precision. Otherwise the cast is
 ineffective.
 
-Example code::
+Example code:
+
+.. code-block:: c++
 
 long f(int x) {
-return (long)(x*1000);
+return (long)(x * 1000);
 }
 
-The result x*1000 is first calculated using int precision. If the result
-exceeds int precision there is loss of precision. Then the result is casted to
-long.
+The result ``x * 1000`` is first calculated using ``int`` precision. If the
+result exceeds ``int`` precision there is loss of precision. Then the result is
+casted to ``long``.
 
 If there is no loss of precision then the cast can be removed or you can
-explicitly cast to int instead.
+explicitly cast to ``int`` instead.
 
 If you want to avoid loss of precision then put the cast in a proper location,
-for instance::
+for instance:
+
+.. code-block:: c++
 
 long f(int x) {
 return (long)x * 1000;
@@ -32,8 +36,10 @@
 --
 
 Forgetting to place the cast at all is at least as dangerous and at least as
-common as misplacing it. If option ``CheckImplicitCasts`` is enabled (default)
-the checker also detects these cases, for instance::
+common as misplacing it. If :option:`CheckImplicitCasts` is enabled the check
+also detects these cases, for instance:
+
+.. code-block:: c++
 
 long f(int x) {
 return x * 1000;
@@ -43,8 +49,17 @@
 --
 
 Currently warnings are only written for integer conversion. No warning is
-written for this code::
+written for this code:
+
+.. code-block:: c++
 
 double f(float x) {
 return (double)(x * 10.0f);
 }
+
+Options
+---
+
+.. option:: CheckImplicitCasts
+
+   If non-zero, enables detection of implicit casts. Default is non-zero.
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/readability-braces-around-statements.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/readability-braces-around-statements.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/readability-braces-around-statements.rst
@@ -11,14 +11,14 @@
 
 Before:
 
-.. code:: c++
+.. code-block:: c++
 
   if (condition)
 statement;
 
 After:
 
-.. code:: c++
+.. code-block:: c++
 
   if (condition) {
 statement;

Re: [PATCH] D23744: driver: Support checking for rlimits via cmake (when bootstrapping)

2016-08-23 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279559: driver: Support checking for rlimits via cmake (when 
bootstrapping) (authored by cbieneman).

Changed prior to commit:
  https://reviews.llvm.org/D23744?vs=68775=69028#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23744

Files:
  cfe/trunk/CMakeLists.txt
  cfe/trunk/include/clang/Config/config.h.cmake
  cfe/trunk/tools/driver/cc1_main.cpp

Index: cfe/trunk/tools/driver/cc1_main.cpp
===
--- cfe/trunk/tools/driver/cc1_main.cpp
+++ cfe/trunk/tools/driver/cc1_main.cpp
@@ -15,6 +15,7 @@
 
 #include "llvm/Option/Arg.h"
 #include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -37,12 +38,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 
-#ifdef __has_include
-#if __has_include()
-#define HAVE_RLIMITS
+#ifdef CLANG_HAVE_RLIMITS
 #include 
 #endif
-#endif
 
 using namespace clang;
 using namespace llvm::opt;
@@ -73,7 +71,7 @@
 }
 #endif
 
-#ifdef HAVE_RLIMITS
+#ifdef CLANG_HAVE_RLIMITS
 // The amount of stack we think is "sufficient". If less than this much is
 // available, we may be unable to reach our template instantiation depth
 // limit and other similar limits.
Index: cfe/trunk/include/clang/Config/config.h.cmake
===
--- cfe/trunk/include/clang/Config/config.h.cmake
+++ cfe/trunk/include/clang/Config/config.h.cmake
@@ -35,6 +35,9 @@
 /* Define if we have libxml2 */
 #cmakedefine CLANG_HAVE_LIBXML ${CLANG_HAVE_LIBXML}
 
+/* Define if we have sys/resource.h (rlimits) */
+#cmakedefine CLANG_HAVE_RLIMITS ${CLANG_HAVE_RLIMITS}
+
 /* The LLVM product name and version */
 #define BACKEND_PACKAGE_STRING "${BACKEND_PACKAGE_STRING}"
 
Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -177,6 +177,9 @@
   set(CLANG_HAVE_LIBXML 1)
 endif()
 
+include(CheckIncludeFile)
+check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
+
 set(CLANG_RESOURCE_DIR "" CACHE STRING
   "Relative directory from the Clang binary to its resource files.")
 


Index: cfe/trunk/tools/driver/cc1_main.cpp
===
--- cfe/trunk/tools/driver/cc1_main.cpp
+++ cfe/trunk/tools/driver/cc1_main.cpp
@@ -15,6 +15,7 @@
 
 #include "llvm/Option/Arg.h"
 #include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -37,12 +38,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 
-#ifdef __has_include
-#if __has_include()
-#define HAVE_RLIMITS
+#ifdef CLANG_HAVE_RLIMITS
 #include 
 #endif
-#endif
 
 using namespace clang;
 using namespace llvm::opt;
@@ -73,7 +71,7 @@
 }
 #endif
 
-#ifdef HAVE_RLIMITS
+#ifdef CLANG_HAVE_RLIMITS
 // The amount of stack we think is "sufficient". If less than this much is
 // available, we may be unable to reach our template instantiation depth
 // limit and other similar limits.
Index: cfe/trunk/include/clang/Config/config.h.cmake
===
--- cfe/trunk/include/clang/Config/config.h.cmake
+++ cfe/trunk/include/clang/Config/config.h.cmake
@@ -35,6 +35,9 @@
 /* Define if we have libxml2 */
 #cmakedefine CLANG_HAVE_LIBXML ${CLANG_HAVE_LIBXML}
 
+/* Define if we have sys/resource.h (rlimits) */
+#cmakedefine CLANG_HAVE_RLIMITS ${CLANG_HAVE_RLIMITS}
+
 /* The LLVM product name and version */
 #define BACKEND_PACKAGE_STRING "${BACKEND_PACKAGE_STRING}"
 
Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -177,6 +177,9 @@
   set(CLANG_HAVE_LIBXML 1)
 endif()
 
+include(CheckIncludeFile)
+check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
+
 set(CLANG_RESOURCE_DIR "" CACHE STRING
   "Relative directory from the Clang binary to its resource files.")
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23828: Make InitListExpr::isExplicit const

2016-08-24 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279613: [AST] Make InitListExpr::isExplicit const (NFC) 
(authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D23828?vs=69083=69084#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23828

Files:
  cfe/trunk/include/clang/AST/Expr.h

Index: cfe/trunk/include/clang/AST/Expr.h
===
--- cfe/trunk/include/clang/AST/Expr.h
+++ cfe/trunk/include/clang/AST/Expr.h
@@ -3862,7 +3862,7 @@
 
   // Explicit InitListExpr's originate from source code (and have valid source
   // locations). Implicit InitListExpr's are created by the semantic analyzer.
-  bool isExplicit() {
+  bool isExplicit() const {
 return LBraceLoc.isValid() && RBraceLoc.isValid();
   }
 


Index: cfe/trunk/include/clang/AST/Expr.h
===
--- cfe/trunk/include/clang/AST/Expr.h
+++ cfe/trunk/include/clang/AST/Expr.h
@@ -3862,7 +3862,7 @@
 
   // Explicit InitListExpr's originate from source code (and have valid source
   // locations). Implicit InitListExpr's are created by the semantic analyzer.
-  bool isExplicit() {
+  bool isExplicit() const {
 return LBraceLoc.isValid() && RBraceLoc.isValid();
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23815: [Clang-tidy] Documentation style. Two Google checks are aliases

2016-08-24 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279659: Clang-tidy documentation style. Two Google checks 
are aliases. (authored by eugenezelenko).

Changed prior to commit:
  https://reviews.llvm.org/D23815?vs=69138=69161#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23815

Files:
  
clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-namespace-comments.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/llvm-namespace-comment.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-control-flow.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-redundant-smartptr-get.rst

Index: clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst
@@ -1,16 +1,10 @@
 .. title:: clang-tidy - google-readability-redundant-smartptr-get
+.. meta::
+   :http-equiv=refresh: 5;URL=readability-redundant-smartptr-get.html
 
 google-readability-redundant-smartptr-get
 =
 
-
-Find and remove redundant calls to smart pointer's ``.get()`` method.
-
-Examples:
-
-.. code:: c++
-
-  ptr.get()->Foo()  ==>  ptr->Foo()
-  *ptr.get()  ==>  *ptr
-  *ptr->get()  ==>  **ptr
-
+The google-readability-redundant-smartptr-get check is an alias, please see
+`readability-redundant-smartptr-get `_
+for more information.
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/llvm-namespace-comment.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/llvm-namespace-comment.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/llvm-namespace-comment.rst
@@ -3,6 +3,8 @@
 llvm-namespace-comment
 ==
 
+`google-readability-namespace-comments` redirects here as an alias for this
+check.
 
 Checks that long namespaces have a closing comment.
 
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-constructor.rst
@@ -9,27 +9,24 @@
 
 Examples:
 
-.. code:: c++
+.. code-block:: c++
 
   std::string('x', 50) str; // should be std::string(50, 'x') 
 
-
 Calling the string-literal constructor with a length bigger than the literal is
 suspicious and adds extra random characters to the string.
 
 Examples:
 
-.. code:: c++
+.. code-block:: c++
 
   std::string("test", 200);   // Will include random characters after "test".
 
-
 Creating an empty string from constructors with parameters is considered
 suspicious. The programmer should use the empty constructor instead.
 
 Examples:
 
-.. code:: c++
+.. code-block:: c++
 
   std::string("test", 0);   // Creation of an empty string.
-
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-namespace-comments.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-namespace-comments.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-namespace-comments.rst
@@ -1,11 +1,9 @@
 .. title:: clang-tidy - google-readability-namespace-comments
+.. meta::
+   :http-equiv=refresh: 5;URL=llvm-namespace-comment.html
 
 google-readability-namespace-comments
 =
 
-
-Checks that long namespaces have a closing comment.
-
-http://llvm.org/docs/CodingStandards.html#namespace-indentation
-
-https://google.github.io/styleguide/cppguide.html#Namespaces
+The google-readability-namespace-comments check is an alias, please see
+`llvm-namespace-comment `_ for more information.
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-definitions-in-headers.rst
@@ -7,7 +7,7 @@
 which can lead to potential ODR violations in case these headers are included
 from multiple translation units.
 
-.. code:: c++
+.. code-block:: c++
 
// Foo.h
int a = 1; // Warning: variable definition.
@@ -38,9 +38,10 @@
}
 
class A {
-public:
+   public:
  int f1() { return 1; } // OK: 

Re: [PATCH] D24984: [libunwind] Add support for a single-threaded libunwind build

2016-09-28 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL282575: [libunwind] Add support for a single-threaded 
libunwind build (authored by asiri).

Changed prior to commit:
  https://reviews.llvm.org/D24984?vs=72698=72798#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24984

Files:
  libunwind/trunk/CMakeLists.txt
  libunwind/trunk/src/CMakeLists.txt
  libunwind/trunk/src/UnwindCursor.hpp
  libunwind/trunk/src/Unwind_AppleExtras.cpp
  libunwind/trunk/src/config.h

Index: libunwind/trunk/CMakeLists.txt
===
--- libunwind/trunk/CMakeLists.txt
+++ libunwind/trunk/CMakeLists.txt
@@ -107,6 +107,7 @@
 option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
 option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
 option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
+option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
 
 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
@@ -242,6 +243,11 @@
   list(APPEND LIBUNWIND_COMPILE_FLAGS -D_LIBUNWIND_IS_NATIVE_ONLY)
 endif()
 
+# Threading-support
+if (NOT LIBUNWIND_ENABLE_THREADS)
+  list(APPEND LIBUNWIND_COMPILE_FLAGS -D_LIBUNWIND_HAS_NO_THREADS)
+endif()
+
 # ARM WMMX register support
 if (LIBUNWIND_ENABLE_ARM_WMMX)
   # __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not
Index: libunwind/trunk/src/Unwind_AppleExtras.cpp
===
--- libunwind/trunk/src/Unwind_AppleExtras.cpp
+++ libunwind/trunk/src/Unwind_AppleExtras.cpp
@@ -185,21 +185,29 @@
 
 #if !defined(FOR_DYLD) && _LIBUNWIND_BUILD_SJLJ_APIS
 
-#include 
+#ifndef _LIBUNWIND_HAS_NO_THREADS
+  #include 
+#else
+  _Unwind_FunctionContext *fc_ = nullptr;
+#endif
 
 // Accessors to get get/set linked list of frames for sjlj based execeptions.
 _LIBUNWIND_HIDDEN
 struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() {
+#ifndef _LIBUNWIND_HAS_NO_THREADS
   return (struct _Unwind_FunctionContext *)
 _pthread_getspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key);
+#else
+  return fc_;
+#endif
 }
 
 _LIBUNWIND_HIDDEN
 void __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) {
+#ifndef _LIBUNWIND_HAS_NO_THREADS
   _pthread_setspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key, fc);
+#else
+  fc_ = fc;
+#endif
 }
 #endif
-
-
-
-
Index: libunwind/trunk/src/config.h
===
--- libunwind/trunk/src/config.h
+++ libunwind/trunk/src/config.h
@@ -85,13 +85,20 @@
   } while (0)
 #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__)
 
+#if defined(_LIBUNWIND_HAS_NO_THREADS)
+  // only used with pthread calls, not needed for the single-threaded builds
+  #define _LIBUNWIND_LOG_NON_ZERO(x)
+#endif
+
 // Macros that define away in non-Debug builds
 #ifdef NDEBUG
   #define _LIBUNWIND_DEBUG_LOG(msg, ...)
   #define _LIBUNWIND_TRACE_API(msg, ...)
   #define _LIBUNWIND_TRACING_UNWINDING 0
   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
-  #define _LIBUNWIND_LOG_NON_ZERO(x) x
+  #ifndef _LIBUNWIND_LOG_NON_ZERO
+#define _LIBUNWIND_LOG_NON_ZERO(x) x
+  #endif
 #else
   #ifdef __cplusplus
 extern "C" {
@@ -102,12 +109,14 @@
 }
   #endif
   #define _LIBUNWIND_DEBUG_LOG(msg, ...)  _LIBUNWIND_LOG(msg, __VA_ARGS__)
-  #define _LIBUNWIND_LOG_NON_ZERO(x) \
-do { \
-  int _err = x; \
-  if ( _err != 0 ) \
-_LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
- } while (0)
+  #ifndef _LIBUNWIND_LOG_NON_ZERO
+#define _LIBUNWIND_LOG_NON_ZERO(x) \
+  do { \
+int _err = x; \
+if ( _err != 0 ) \
+  _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
+   } while (0)
+  #endif
   #define _LIBUNWIND_TRACE_API(msg, ...) \
 do { \
   if ( logAPIs() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
Index: libunwind/trunk/src/UnwindCursor.hpp
===
--- libunwind/trunk/src/UnwindCursor.hpp
+++ libunwind/trunk/src/UnwindCursor.hpp
@@ -16,7 +16,9 @@
 #include 
 #include 
 #include 
-#include 
+#ifndef _LIBUNWIND_HAS_NO_THREADS
+  #include 
+#endif
 #include 
 
 #ifdef __APPLE__
@@ -60,7 +62,9 @@
 
   // These fields are all static to avoid needing an initializer.
   // There is only one instance of this class per process.
+#ifndef _LIBUNWIND_HAS_NO_THREADS
   static pthread_rwlock_t _lock;
+#endif
 #ifdef __APPLE__
   static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide);
   static bool _registeredForDyldUnloads;
@@ -87,8 +91,10 @@
 template 
 typename DwarfFDECache::entry 

[PATCH] D26024: [Xray] Don't generate output for xray tests

2016-10-27 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285276: [Xray] Don't generate output for xray tests 
(authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D26024?vs=75991=75994#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26024

Files:
  cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c
  cfe/trunk/test/Driver/XRay/xray-instrument-os.c


Index: cfe/trunk/test/Driver/XRay/xray-instrument-os.c
===
--- cfe/trunk/test/Driver/XRay/xray-instrument-os.c
+++ cfe/trunk/test/Driver/XRay/xray-instrument-os.c
@@ -1,4 +1,4 @@
-// RUN: not %clang -v -fxray-instrument -c %s
+// RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
 // XFAIL: -linux-
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm
 typedef int a;
Index: cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c
===
--- cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c
+++ cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c
@@ -1,4 +1,4 @@
-// RUN: not %clang -v -fxray-instrument -c %s
+// RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
 // XFAIL: amd64-, x86_64-, x86_64h-, arm
 // REQUIRES: linux
 typedef int a;


Index: cfe/trunk/test/Driver/XRay/xray-instrument-os.c
===
--- cfe/trunk/test/Driver/XRay/xray-instrument-os.c
+++ cfe/trunk/test/Driver/XRay/xray-instrument-os.c
@@ -1,4 +1,4 @@
-// RUN: not %clang -v -fxray-instrument -c %s
+// RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
 // XFAIL: -linux-
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm
 typedef int a;
Index: cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c
===
--- cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c
+++ cfe/trunk/test/Driver/XRay/xray-instrument-cpu.c
@@ -1,4 +1,4 @@
-// RUN: not %clang -v -fxray-instrument -c %s
+// RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
 // XFAIL: amd64-, x86_64-, x86_64h-, arm
 // REQUIRES: linux
 typedef int a;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25876: [analyzer] Report CFNumberGetValue API misuse

2016-10-26 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285253: [analyzer] Report CFNumberGetValue API misuse 
(authored by zaks).

Changed prior to commit:
  https://reviews.llvm.org/D25876?vs=75488=75961#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25876

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
  cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  cfe/trunk/test/Analysis/CFNumber.c

Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -586,8 +586,8 @@
 
 let ParentPackage = CoreFoundation in {
 
-def CFNumberCreateChecker : Checker<"CFNumber">,
-  HelpText<"Check for proper uses of CFNumberCreate">,
+def CFNumberChecker : Checker<"CFNumber">,
+  HelpText<"Check for proper uses of CFNumber APIs">,
   DescFile<"BasicObjCFoundationChecks.cpp">;
 
 def CFRetainReleaseChecker : Checker<"CFRetainRelease">,
Index: cfe/trunk/test/Analysis/CFNumber.c
===
--- cfe/trunk/test/Analysis/CFNumber.c
+++ cfe/trunk/test/Analysis/CFNumber.c
@@ -13,21 +13,35 @@
kCFNumberMaxType = 16 };
 typedef CFIndex CFNumberType;
 typedef const struct __CFNumber * CFNumberRef;
+typedef unsigned char Boolean;
 extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
+Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
 
-CFNumberRef f1(unsigned char x) {
-  return CFNumberCreate(0, kCFNumberSInt16Type, );  // expected-warning{{An 8 bit integer is used to initialize a CFNumber object that represents a 16 bit integer. 8 bits of the CFNumber value will be garbage}}
+__attribute__((cf_returns_retained)) CFNumberRef f1(unsigned char x) {
+  return CFNumberCreate(0, kCFNumberSInt16Type, );  // expected-warning{{An 8-bit integer is used to initialize a CFNumber object that represents a 16-bit integer; 8 bits of the CFNumber value will be garbage}}
 }
 
 __attribute__((cf_returns_retained)) CFNumberRef f2(unsigned short x) {
-  return CFNumberCreate(0, kCFNumberSInt8Type, ); // expected-warning{{A 16 bit integer is used to initialize a CFNumber object that represents an 8 bit integer. 8 bits of the input integer will be lost}}
+  return CFNumberCreate(0, kCFNumberSInt8Type, ); // expected-warning{{A 16-bit integer is used to initialize a CFNumber object that represents an 8-bit integer; 8 bits of the integer value will be lost}}
 }
 
 // test that the attribute overrides the naming convention.
 __attribute__((cf_returns_not_retained)) CFNumberRef CreateNum(unsigned char x) {
   return CFNumberCreate(0, kCFNumberSInt8Type, ); // expected-warning{{leak}}
 }
 
-CFNumberRef f3(unsigned i) {
-  return CFNumberCreate(0, kCFNumberLongType, ); // expected-warning{{A 32 bit integer is used to initialize a CFNumber object that represents a 64 bit integer}}
+__attribute__((cf_returns_retained)) CFNumberRef f3(unsigned i) {
+  return CFNumberCreate(0, kCFNumberLongType, ); // expected-warning{{A 32-bit integer is used to initialize a CFNumber object that represents a 64-bit integer}}
+}
+
+unsigned char getValueTest1(CFNumberRef x) {
+  unsigned char scalar = 0;
+  CFNumberGetValue(x, kCFNumberSInt16Type, );  // expected-warning{{A CFNumber object that represents a 16-bit integer is used to initialize an 8-bit integer; 8 bits of the CFNumber value will overwrite adjacent storage}}
+  return scalar;
+}
+
+unsigned char getValueTest2(CFNumberRef x) {
+  unsigned short scalar = 0;
+  CFNumberGetValue(x, kCFNumberSInt8Type, );  // expected-warning{{A CFNumber object that represents an 8-bit integer is used to initialize a 16-bit integer; 8 bits of the integer value will be garbage}}
+  return scalar;
 }
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -336,15 +336,15 @@
 }
 
 //===--===//
-// Error reporting.
+// Checking for mismatched types passed to CFNumberCreate/CFNumberGetValue.
 //===--===//
 
 namespace {
-class CFNumberCreateChecker : public Checker< check::PreStmt > {
+class CFNumberChecker : public Checker< check::PreStmt > {
   mutable std::unique_ptr BT;
-  mutable IdentifierInfo* II;
+  mutable IdentifierInfo *ICreate, *IGetValue;
 public:
-  CFNumberCreateChecker() : II(nullptr) {}
+  CFNumberChecker() : ICreate(nullptr), IGetValue(nullptr) {}
 
   void checkPreStmt(const CallExpr *CE, CheckerContext ) const;
 
@@ -425,18 

[PATCH] D25902: [AVX-512] Fix the operand order for all calls to __builtin_ia32_vfmaddss3_mask.

2016-10-25 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285175: [AVX-512] Fix the operand order for all calls to 
__builtin_ia32_vfmaddss3_mask. (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D25902?vs=75557=75830#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25902

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

Index: cfe/trunk/lib/Headers/avx512fintrin.h
===
--- cfe/trunk/lib/Headers/avx512fintrin.h
+++ cfe/trunk/lib/Headers/avx512fintrin.h
@@ -8338,17 +8338,17 @@
 static __inline__ __m128 __DEFAULT_FN_ATTRS
 _mm_mask_fmadd_ss (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B)
 {
- return (__m128) __builtin_ia32_vfmaddss3_mask ((__v4sf) __A,
+ return (__m128) __builtin_ia32_vfmaddss3_mask ((__v4sf) __W,
+  (__v4sf) __A,
   (__v4sf) __B,
-  (__v4sf) __W,
   (__mmask8) __U,
   _MM_FROUND_CUR_DIRECTION);
 }
 
 #define _mm_mask_fmadd_round_ss(W, U, A, B, R) __extension__({\
-  (__m128)__builtin_ia32_vfmaddss3_mask((__v4sf)(__m128)(A), \
-(__v4sf)(__m128)(B), \
-(__v4sf)(__m128)(W), (__mmask8)(U), \
+  (__m128)__builtin_ia32_vfmaddss3_mask((__v4sf)(__m128)(W), \
+(__v4sf)(__m128)(A), \
+(__v4sf)(__m128)(B), (__mmask8)(U), \
 (int)(R)); })
 
 static __inline__ __m128 __DEFAULT_FN_ATTRS
@@ -8386,17 +8386,17 @@
 static __inline__ __m128 __DEFAULT_FN_ATTRS
 _mm_mask_fmsub_ss (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B)
 {
- return (__m128) __builtin_ia32_vfmaddss3_mask ((__v4sf) __A,
+ return (__m128) __builtin_ia32_vfmaddss3_mask ((__v4sf) __W,
+  (__v4sf) __A,
   -(__v4sf) __B,
-  (__v4sf) __W,
   (__mmask8) __U,
   _MM_FROUND_CUR_DIRECTION);
 }
 
 #define _mm_mask_fmsub_round_ss(W, U, A, B, R) __extension__ ({\
-  (__m128)__builtin_ia32_vfmaddss3_mask((__v4sf)(__m128)(A), \
--(__v4sf)(__m128)(B), \
-(__v4sf)(__m128)(W), (__mmask8)(U), \
+  (__m128)__builtin_ia32_vfmaddss3_mask((__v4sf)(__m128)(W), \
+(__v4sf)(__m128)(A), \
+(__v4sf)(__m128)(B), (__mmask8)(U), \
 (int)(R)); })
 
 static __inline__ __m128 __DEFAULT_FN_ATTRS
@@ -8434,17 +8434,17 @@
 static __inline__ __m128 __DEFAULT_FN_ATTRS
 _mm_mask_fnmadd_ss (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B)
 {
- return (__m128) __builtin_ia32_vfmaddss3_mask (-(__v4sf) __A,
+ return (__m128) __builtin_ia32_vfmaddss3_mask ((__v4sf) __W,
+  -(__v4sf) __A,
   (__v4sf) __B,
-  (__v4sf) __W,
   (__mmask8) __U,
   _MM_FROUND_CUR_DIRECTION);
 }
 
 #define _mm_mask_fnmadd_round_ss(W, U, A, B, R) __extension__ ({\
-  (__m128)__builtin_ia32_vfmaddss3_mask(-(__v4sf)(__m128)(A), \
-(__v4sf)(__m128)(B), \
-(__v4sf)(__m128)(W), (__mmask8)(U), \
+  (__m128)__builtin_ia32_vfmaddss3_mask((__v4sf)(__m128)(W), \
+-(__v4sf)(__m128)(A), \
+(__v4sf)(__m128)(B), (__mmask8)(U), \
 (int)(R)); })
 
 static __inline__ __m128 __DEFAULT_FN_ATTRS
@@ -8482,17 +8482,17 @@
 static __inline__ __m128 __DEFAULT_FN_ATTRS
 _mm_mask_fnmsub_ss (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B)
 {
- return (__m128) __builtin_ia32_vfmaddss3_mask (-(__v4sf) __A,
+ return (__m128) __builtin_ia32_vfmaddss3_mask ((__v4sf) __W,
+  -(__v4sf) __A,
   -(__v4sf) __B,
-  (__v4sf) __W,
   (__mmask8) __U,
   _MM_FROUND_CUR_DIRECTION);
 }
 
 #define _mm_mask_fnmsub_round_ss(W, U, A, B, R) __extension__ ({\
-  (__m128)__builtin_ia32_vfmaddss3_mask(-(__v4sf)(__m128)(A), \
--(__v4sf)(__m128)(B), \
-(__v4sf)(__m128)(W), (__mmask8)(U), \
+  (__m128)__builtin_ia32_vfmaddss3_mask((__v4sf)(__m128)(W), \
+-(__v4sf)(__m128)(A), \
+-(__v4sf)(__m128)(B), (__mmask8)(U), \
 (int)(R)); })
 
 static __inline__ __m128 __DEFAULT_FN_ATTRS
@@ -8530,17 +8530,17 @@
 static __inline__ __m128d __DEFAULT_FN_ATTRS
 _mm_mask_fmadd_sd (__m128d __W, __mmask8 __U, __m128d __A, __m128d __B)
 {
- return (__m128d) __builtin_ia32_vfmaddsd3_mask ( (__v2df) __A,
+ return (__m128d) __builtin_ia32_vfmaddsd3_mask ( (__v2df) __W,
+  (__v2df) __A,
   (__v2df) __B,
-  (__v2df) __W,
   (__mmask8) __U,
   _MM_FROUND_CUR_DIRECTION);
 

[PATCH] D25284: AvailabilityAttrs: Delay partial availability diagnostics

2016-10-28 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285457: [Sema] Delay partial availability diagnostics, just 
like deprecated (authored by epilk).

Changed prior to commit:
  https://reviews.llvm.org/D25284?vs=74738=76250#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25284

Files:
  cfe/trunk/include/clang/Sema/DelayedDiagnostic.h
  cfe/trunk/lib/Sema/DelayedDiagnostic.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/SemaObjC/unguarded-availability.m

Index: cfe/trunk/test/SemaObjC/unguarded-availability.m
===
--- cfe/trunk/test/SemaObjC/unguarded-availability.m
+++ cfe/trunk/test/SemaObjC/unguarded-availability.m
@@ -63,7 +63,7 @@
 #ifdef OBJCPP
 // expected-note@+2 {{marked partial here}}
 #endif
-typedef int int_10_12 AVAILABLE_10_12; // expected-note 3 {{'int_10_12' has been explicitly marked partial here}}
+typedef int int_10_12 AVAILABLE_10_12; // expected-note 2 {{'int_10_12' has been explicitly marked partial here}}
 
 void use_typedef() {
   int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}}
@@ -127,8 +127,7 @@
 
 void test_params(int_10_12 x); // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}}
 
-// FIXME: This should be fine!
-void test_params2(int_10_12 x) AVAILABLE_10_12; // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}}
+void test_params2(int_10_12 x) AVAILABLE_10_12; // no warn
 
 #ifdef OBJCPP
 
Index: cfe/trunk/lib/Sema/DelayedDiagnostic.cpp
===
--- cfe/trunk/lib/Sema/DelayedDiagnostic.cpp
+++ cfe/trunk/lib/Sema/DelayedDiagnostic.cpp
@@ -20,50 +20,41 @@
 using namespace sema;
 
 DelayedDiagnostic
-DelayedDiagnostic::makeAvailability(AvailabilityResult AD,
+DelayedDiagnostic::makeAvailability(AvailabilityResult AR,
 SourceLocation Loc,
 const NamedDecl *D,
 const ObjCInterfaceDecl *UnknownObjCClass,
 const ObjCPropertyDecl  *ObjCProperty,
 StringRef Msg,
 bool ObjCPropertyAccess) {
   DelayedDiagnostic DD;
-  switch (AD) {
-  case AR_Deprecated:
-DD.Kind = Deprecation;
-break;
-  case AR_Unavailable:
-DD.Kind = Unavailable;
-break;
-  default:
-llvm_unreachable("partial diags should not be delayed");
-  }
+  DD.Kind = Availability;
   DD.Triggered = false;
   DD.Loc = Loc;
-  DD.DeprecationData.Decl = D;
-  DD.DeprecationData.UnknownObjCClass = UnknownObjCClass;
-  DD.DeprecationData.ObjCProperty = ObjCProperty;
+  DD.AvailabilityData.Decl = D;
+  DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
+  DD.AvailabilityData.ObjCProperty = ObjCProperty;
   char *MessageData = nullptr;
   if (Msg.size()) {
 MessageData = new char [Msg.size()];
 memcpy(MessageData, Msg.data(), Msg.size());
   }
 
-  DD.DeprecationData.Message = MessageData;
-  DD.DeprecationData.MessageLen = Msg.size();
-  DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess;
+  DD.AvailabilityData.Message = MessageData;
+  DD.AvailabilityData.MessageLen = Msg.size();
+  DD.AvailabilityData.AR = AR;
+  DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
   return DD;
 }
 
 void DelayedDiagnostic::Destroy() {
-  switch (static_cast(Kind)) {
+  switch (Kind) {
   case Access: 
 getAccessData().~AccessedEntity(); 
 break;
 
-  case Deprecation:
-  case Unavailable:
-delete [] DeprecationData.Message;
+  case Availability:
+delete[] AvailabilityData.Message;
 break;
 
   case ForbiddenType:
Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -6510,9 +6510,6 @@
 break;
 
   case AR_NotYetIntroduced:
-assert(!S.getCurFunctionOrMethodDecl() &&
-   "Function-level partial availablity should not be diagnosed here!");
-
 diag = diag::warn_partial_availability;
 diag_message = diag::warn_partial_message;
 diag_fwdclass_message = diag::warn_partial_fwdclass_message;
@@ -6585,15 +6582,14 @@
 
 static void handleDelayedAvailabilityCheck(Sema , DelayedDiagnostic ,
Decl *Ctx) {
-  assert(DD.Kind == DelayedDiagnostic::Deprecation ||
- DD.Kind == DelayedDiagnostic::Unavailable);
-  AvailabilityResult AR = DD.Kind == DelayedDiagnostic::Deprecation
-  ? AR_Deprecated
-  : AR_Unavailable;
+  assert(DD.Kind == DelayedDiagnostic::Availability &&
+ "Expected an availability diagnostic 

[PATCH] D22770: [Sema, NFC] Reset HasFallthroughStmt when clearing FunctionScopeInfo

2016-11-09 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL286409: [Sema][NFC] Reset HasFallthroughStmt when clearing 
FunctionScopeInfo (authored by epilk).

Changed prior to commit:
  https://reviews.llvm.org/D22770?vs=65380=77399#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22770

Files:
  cfe/trunk/lib/Sema/ScopeInfo.cpp


Index: cfe/trunk/lib/Sema/ScopeInfo.cpp
===
--- cfe/trunk/lib/Sema/ScopeInfo.cpp
+++ cfe/trunk/lib/Sema/ScopeInfo.cpp
@@ -29,6 +29,7 @@
   HasIndirectGoto = false;
   HasDroppedStmt = false;
   HasOMPDeclareReductionCombiner = false;
+  HasFallthroughStmt = false;
   HasPotentialAvailabilityViolations = false;
   ObjCShouldCallSuper = false;
   ObjCIsDesignatedInit = false;


Index: cfe/trunk/lib/Sema/ScopeInfo.cpp
===
--- cfe/trunk/lib/Sema/ScopeInfo.cpp
+++ cfe/trunk/lib/Sema/ScopeInfo.cpp
@@ -29,6 +29,7 @@
   HasIndirectGoto = false;
   HasDroppedStmt = false;
   HasOMPDeclareReductionCombiner = false;
+  HasFallthroughStmt = false;
   HasPotentialAvailabilityViolations = false;
   ObjCShouldCallSuper = false;
   ObjCIsDesignatedInit = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25448: [ubsan] Use the object pointer's type info for devirtualized calls

2016-10-19 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284636: [ubsan] Use the object pointer's type info for 
devirtualized calls (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D25448?vs=75168=75211#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25448

Files:
  cfe/trunk/lib/CodeGen/CGExprCXX.cpp
  cfe/trunk/test/CodeGenCXX/ubsan-devirtualized-calls.cpp

Index: cfe/trunk/test/CodeGenCXX/ubsan-devirtualized-calls.cpp
===
--- cfe/trunk/test/CodeGenCXX/ubsan-devirtualized-calls.cpp
+++ cfe/trunk/test/CodeGenCXX/ubsan-devirtualized-calls.cpp
@@ -0,0 +1,91 @@
+// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -emit-llvm -fsanitize=vptr %s -o - | FileCheck %s
+
+struct Base1 {
+  virtual void f1() {}
+};
+
+struct Base2 {
+  virtual void f1() {}
+};
+
+struct Derived1 final : Base1 {
+  void f1() override {}
+};
+
+struct Derived2 final : Base1, Base2 {
+  void f1() override {}
+};
+
+// PR13127 documents some missed devirtualization opportunities, including
+// devirt for methods marked 'final'. We can enable the checks marked 'PR13127'
+// if we implement this in the frontend.
+struct Derived3 : Base1 {
+  void f1() override /* nofinal */ {}
+};
+
+struct Derived4 final : Base1 {
+  void f1() override final {}
+};
+
+// CHECK: [[UBSAN_TI_DERIVED1_1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived1 to i8*
+// CHECK: [[UBSAN_TI_DERIVED2_1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived2 to i8*
+// CHECK: [[UBSAN_TI_DERIVED2_2:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived2 to i8*
+// PR13127: [[UBSAN_TI_DERIVED3:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived3 to i8*
+// PR13127: [[UBSAN_TI_BASE1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI5Base1 to i8*
+// PR13127: [[UBSAN_TI_DERIVED4_1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived4 to i8*
+// PR13127: [[UBSAN_TI_DERIVED4_2:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived4 to i8*
+
+// CHECK-LABEL: define void @_Z2t1v
+void t1() {
+  Derived1 d1;
+  static_cast()->f1(); //< Devirt Base1::f1 to Derived1::f1.
+  // CHECK: handler.dynamic_type_cache_miss:
+  // CHECK-NEXT: %[[D1:[0-9]+]] = ptrtoint %struct.Derived1* %d1 to i64, !nosanitize
+  // CHECK-NEXT: call void @{{[_a-z]+}}({{.*}} [[UBSAN_TI_DERIVED1_1]] {{.*}}, i64 %[[D1]]
+}
+
+// CHECK-LABEL: define void @_Z2t2v
+void t2() {
+  Derived2 d2;
+  static_cast()->f1(); //< Devirt Base1::f1 to Derived2::f1.
+  // CHECK: handler.dynamic_type_cache_miss:
+  // CHECK-NEXT: %[[D2_1:[0-9]+]] = ptrtoint %struct.Derived2* %d2 to i64, !nosanitize
+  // CHECK-NEXT: call void @{{[_a-z]+}}({{.*}} [[UBSAN_TI_DERIVED2_1]] {{.*}}, i64 %[[D2_1]]
+}
+
+// CHECK-LABEL: define void @_Z2t3v
+void t3() {
+  Derived2 d2;
+  static_cast()->f1(); //< Devirt Base2::f1 to Derived2::f1.
+  // CHECK: handler.dynamic_type_cache_miss:
+  // CHECK-NEXT: %[[D2_2:[0-9]+]] = ptrtoint %struct.Derived2* %d2 to i64, !nosanitize
+  // CHECK-NEXT: call void @{{[_a-z]+}}({{.*}} [[UBSAN_TI_DERIVED2_2]] {{.*}}, i64 %[[D2_2]]
+}
+
+// PR13127-LABEL: define void @_Z2t4v
+void t4() {
+  Base1 p;
+  Derived3 *badp = static_cast(); //< Check that  isa Derived3.
+  // PR13127: handler.dynamic_type_cache_miss
+  // PR13127: %[[P1:[0-9]+]] = ptrtoint %struct.Derived3* {{%[0-9]+}} to i64, !nosanitize
+  // PR13127-NEXT: call void @{{[_a-z]+}}({{.*}} [[UBSAN_TI_DERIVED3]] {{.*}}, i64 %[[P1]]
+
+  static_cast(badp)->f1(); //< No devirt, test 'badp isa Base1'.
+  // PR13127: handler.dynamic_type_cache_miss
+  // PR13127: %[[BADP1:[0-9]+]] = ptrtoint %struct.Base1* {{%[0-9]+}} to i64, !nosanitize
+  // PR13127-NEXT: call void @{{[_a-z]+}}({{.*}} [[UBSAN_TI_BASE1]] {{.*}}, i64 %[[BADP1]]
+}
+
+// PR13127-LABEL: define void @_Z2t5v
+void t5() {
+  Base1 p;
+  Derived4 *badp = static_cast(); //< Check that  isa Derived4.
+  // PR13127: handler.dynamic_type_cache_miss:
+  // PR13127: %[[P1:[0-9]+]] = ptrtoint %struct.Derived4* {{%[0-9]+}} to i64, !nosanitize
+  // PR13127-NEXT: call void @{{[_a-z]+}}({{.*}} [[UBSAN_TI_DERIVED4_1]] {{.*}}, i64 %[[P1]]
+
+  static_cast(badp)->f1(); //< Devirt Base1::f1 to Derived4::f1.
+  // PR13127: handler.dynamic_type_cache_miss1:
+  // PR13127: %[[BADP1:[0-9]+]] = ptrtoint %struct.Derived4* {{%[0-9]+}} to i64, !nosanitize
+  // PR13127-NEXT: call void @{{[_a-z]+}}({{.*}} [[UBSAN_TI_DERIVED4_2]] {{.*}}, i64 %[[BADP1]]
+}
Index: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
===
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp
@@ -241,6 +241,9 @@
 
   llvm::FunctionType *Ty = CGM.getTypes().GetFunctionType(*FInfo);
 
+  // FIXME: Uses of 'MD' past this point need to be audited. We may need 

[PATCH] D24669: {Sema] Gcc compatibility of vector shift.

2016-10-19 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284579: [Sema] Gcc compatibility of vector shift (authored 
by asbokhan).

Changed prior to commit:
  https://reviews.llvm.org/D24669?vs=74269=75130#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24669

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/CodeGen/vecshift.c
  cfe/trunk/test/Sema/vecshift.c

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2305,6 +2305,9 @@
   "cannot convert between vector and non-scalar values (%0 and %1)">;
 def err_typecheck_vector_lengths_not_equal : Error<
   "vector operands do not have the same number of elements (%0 and %1)">;
+def warn_typecheck_vector_element_sizes_not_equal : Warning<
+  "vector operands do not have the same elements sizes (%0 and %1)">,
+  InGroup>, DefaultError;
 def err_ext_vector_component_exceeds_length : Error<
   "vector component access exceeds type %0">;
 def err_ext_vector_component_name_illegal : Error<
Index: cfe/trunk/test/Sema/vecshift.c
===
--- cfe/trunk/test/Sema/vecshift.c
+++ cfe/trunk/test/Sema/vecshift.c
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DERR -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-error-vec-elem-size -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DEXT -DERR -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DEXT -Wno-error-vec-elem-size -verify %s
 
+#ifdef EXT
 typedef __attribute__((__ext_vector_type__(8))) char vector_char8;
 typedef __attribute__((__ext_vector_type__(8))) short vector_short8;
 typedef __attribute__((__ext_vector_type__(8))) int vector_int8;
@@ -12,6 +16,20 @@
 typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4;
 typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4;
 typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4;
+#else
+typedef __attribute__((vector_size(8))) char vector_char8;
+typedef __attribute__((vector_size(16))) short vector_short8;
+typedef __attribute__((vector_size(32))) int vector_int8;
+typedef __attribute__((vector_size(8))) unsigned char vector_uchar8;
+typedef __attribute__((vector_size(16))) unsigned short vector_ushort8;
+typedef __attribute__((vector_size(32))) unsigned int vector_uint8;
+typedef __attribute__((vector_size(4))) char vector_char4;
+typedef __attribute__((vector_size(4))) short vector_short4;
+typedef __attribute__((vector_size(16))) int vector_int4;
+typedef __attribute__((vector_size(4))) unsigned char vector_uchar4;
+typedef __attribute__((vector_size(8))) unsigned short vector_ushort4;
+typedef __attribute__((vector_size(16))) unsigned int vector_uint4;
+#endif
 
 char c;
 short s;
@@ -48,16 +66,30 @@
   vus8 = 1 << vus8;
 
   vc8 = vc8 << vc8;
-  vi8 = vi8 << vuc8;
-  vuc8 = vuc8 << vi8;
-  vus8 = vus8 << vui8;
-  vui8 = vui8 << vs8;
+#ifdef ERR
+  vi8 = vi8 << vuc8; // expected-error {{vector operands do not have the same elements sizes}}
+  vuc8 = vuc8 << vi8; // expected-error {{vector operands do not have the same elements sizes}}
+  vus8 = vus8 << vui8; // expected-error {{vector operands do not have the same elements sizes}}
+  vui8 = vui8 << vs8; // expected-error {{vector operands do not have the same elements sizes}}
+#else
+  vi8 = vi8 << vuc8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vuc8 = vuc8 << vi8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vus8 = vus8 << vui8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vui8 = vui8 << vs8; // expected-warning {{vector operands do not have the same elements sizes}}
+#endif
 
   vc8 <<= vc8;
-  vi8 <<= vuc8;
-  vuc8 <<= vi8;
-  vus8 <<= vui8;
-  vui8 <<= vs8;
+#ifdef ERR
+  vi8 <<= vuc8; // expected-error {{vector operands do not have the same elements sizes}}
+  vuc8 <<= vi8; // expected-error {{vector operands do not have the same elements sizes}}
+  vus8 <<= vui8; // expected-error {{vector operands do not have the same elements sizes}}
+  vui8 <<= vs8; // expected-error {{vector operands do not have the same elements sizes}}
+#else
+  vi8 <<= vuc8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vuc8 <<= vi8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vus8 <<= vui8; // expected-warning {{vector operands do not have the same elements sizes}}
+  vui8 <<= vs8; // expected-warning {{vector operands do not have the same elements sizes}}
+#endif
 
   c <<= vc8; // expected-error {{assigning to 'char' from incompatible type}}
   i <<= vuc8; // expected-error 

[PATCH] D22968: [analyzer] A checker for macOS-specific bool- and number-like objects.

2016-10-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284473: [analyzer] Add NumberObjectConversion checker. 
(authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D22968?vs=74969=74979#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22968

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
  cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  cfe/trunk/test/Analysis/Inputs/system-header-simulator-objc.h
  cfe/trunk/test/Analysis/number-object-conversion.cpp
  cfe/trunk/test/Analysis/number-object-conversion.m

Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -474,6 +474,11 @@
 
 let ParentPackage = OSX in {
 
+def NumberObjectConversionChecker : Checker<"NumberObjectConversion">,
+  InPackage,
+  HelpText<"Check for erroneous conversions of objects representing numbers into numbers">,
+  DescFile<"NumberObjectConversionChecker.cpp">;
+
 def MacOSXAPIChecker : Checker<"API">,
   InPackage,
   HelpText<"Check for proper uses of various Apple APIs">,
Index: cfe/trunk/test/Analysis/Inputs/system-header-simulator-objc.h
===
--- cfe/trunk/test/Analysis/Inputs/system-header-simulator-objc.h
+++ cfe/trunk/test/Analysis/Inputs/system-header-simulator-objc.h
@@ -10,10 +10,16 @@
 
 typedef signed long CFIndex;
 typedef signed char BOOL;
+#define YES ((BOOL)1)
+#define NO ((BOOL)0)
+
 typedef unsigned long NSUInteger;
 typedef unsigned short unichar;
 typedef UInt16 UniChar;
 
+#define NULL ((void *)0)
+#define nil ((id)0)
+
 enum {
 NSASCIIStringEncoding = 1,
 NSNEXTSTEPStringEncoding = 2,
@@ -72,6 +78,7 @@
 @end
 @interface NSNumber : NSValue  - (char)charValue;
 - (id)initWithInt:(int)value;
+- (BOOL)boolValue;
 @end   @class NSString;
 @interface NSArray : NSObject   - (NSUInteger)count;
 @end  @interface NSArray (NSArrayCreation)  + (id)array;
Index: cfe/trunk/test/Analysis/number-object-conversion.cpp
===
--- cfe/trunk/test/Analysis/number-object-conversion.cpp
+++ cfe/trunk/test/Analysis/number-object-conversion.cpp
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin10 -w -std=c++11 -analyze -analyzer-checker=osx.NumberObjectConversion %s -verify
+// RUN: %clang_cc1 -triple i386-apple-darwin10 -w -std=c++11 -analyze -analyzer-checker=osx.NumberObjectConversion -analyzer-config osx.NumberObjectConversion:Pedantic=true -DPEDANTIC %s -verify
+
+#define NULL ((void *)0)
+#include "Inputs/system-header-simulator-cxx.h" // for nullptr
+
+class OSBoolean {
+public:
+  virtual bool isTrue() const;
+  virtual bool isFalse() const;
+};
+
+extern const OSBoolean *const 
+extern const OSBoolean *const 
+
+void takes_bool(bool);
+
+void bad(const OSBoolean *p) {
+#ifdef PEDANTIC
+  if (p) {} // expected-warning{{Converting 'const class OSBoolean *' to a plain boolean value for branching; please compare the pointer to NULL or nullptr instead to suppress this warning}}
+  if (!p) {} // expected-warning{{Converting 'const class OSBoolean *' to a plain boolean value for branching; please compare the pointer to NULL or nullptr instead to suppress this warning}}
+  p ? 1 : 2; // expected-warning{{Converting 'const class OSBoolean *' to a plain boolean value for branching; please compare the pointer to NULL or nullptr instead to suppress this warning}}
+  (bool)p; // expected-warning{{Converting 'const class OSBoolean *' to a plain bool value; please compare the pointer to NULL or nullptr instead to suppress this warning}}
+#endif
+  bool x = p; // expected-warning{{Converting 'const class OSBoolean *' to a plain bool value; pointer value is being used instead}}
+  x = p; // expected-warning{{Converting 'const class OSBoolean *' to a plain bool value; pointer value is being used instead}}
+  takes_bool(p); // expected-warning{{Converting 'const class OSBoolean *' to a plain bool value; pointer value is being used instead}}
+  takes_bool(x); // no-warning
+}
+
+typedef bool sugared_bool;
+typedef const OSBoolean *sugared_OSBoolean;
+void bad_sugared(sugared_OSBoolean p) {
+  sugared_bool x = p; // expected-warning{{Converting 'const class OSBoolean *' to a plain bool value; pointer value is being used instead}}
+}
+
+void good(const OSBoolean *p) {
+  bool x = p->isTrue(); // no-warning
+  (bool)p->isFalse(); // no-warning
+  if (p == kOSBooleanTrue) {} // no-warning
+}
+
+void suppression(const OSBoolean *p) {
+  if (p == NULL) {} // no-warning
+  bool y = (p == nullptr); // no-warning
+}
+
+// Conversion of a pointer to an intptr_t is fine.
+typedef 

[PATCH] D19854: Define Contiki OS toolchain

2016-10-14 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284278: Define Contiki OS toolchain (authored by dlkreitz).

Changed prior to commit:
  https://reviews.llvm.org/D19854?vs=70076=74741#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D19854

Files:
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/ToolChains.cpp
  cfe/trunk/lib/Driver/ToolChains.h
  cfe/trunk/test/Driver/fsanitize.c


Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -397,6 +397,7 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP
+// RUN: %clang -target i386-contiki-unknown -fsanitize=safe-stack -### %s 2>&1 
| FileCheck %s -check-prefix=NO-SP
 // NO-SP-NOT: stack-protector
 // NO-SP: "-fsanitize=safe-stack"
 // SP: "-fsanitize=safe-stack"
Index: cfe/trunk/lib/Driver/ToolChains.h
===
--- cfe/trunk/lib/Driver/ToolChains.h
+++ cfe/trunk/lib/Driver/ToolChains.h
@@ -1249,6 +1249,14 @@
   Tool *buildLinker() const override;
 };
 
+class LLVM_LIBRARY_VISIBILITY Contiki : public Generic_ELF {
+public:
+  Contiki(const Driver , const llvm::Triple ,
+  const llvm::opt::ArgList );
+
+  SanitizerMask getSupportedSanitizers() const override;
+};
+
 } // end namespace toolchains
 } // end namespace driver
 } // end namespace clang
Index: cfe/trunk/lib/Driver/ToolChains.cpp
===
--- cfe/trunk/lib/Driver/ToolChains.cpp
+++ cfe/trunk/lib/Driver/ToolChains.cpp
@@ -5305,3 +5305,14 @@
   Res |= SanitizerKind::Vptr;
   return Res;
 }
+
+Contiki::Contiki(const Driver , const llvm::Triple , const ArgList 
)
+: Generic_ELF(D, Triple, Args) {}
+
+SanitizerMask Contiki::getSupportedSanitizers() const {
+  const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  if (IsX86)
+Res |= SanitizerKind::SafeStack;
+  return Res;
+}
Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -3120,6 +3120,9 @@
 case llvm::Triple::PS4:
   TC = new toolchains::PS4CPU(*this, Target, Args);
   break;
+case llvm::Triple::Contiki:
+  TC = new toolchains::Contiki(*this, Target, Args);
+  break;
 default:
   // Of these targets, Hexagon is the only one that might have
   // an OS of Linux, in which case it got handled above already.


Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -397,6 +397,7 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
+// RUN: %clang -target i386-contiki-unknown -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
 // NO-SP-NOT: stack-protector
 // NO-SP: "-fsanitize=safe-stack"
 // SP: "-fsanitize=safe-stack"
Index: cfe/trunk/lib/Driver/ToolChains.h
===
--- cfe/trunk/lib/Driver/ToolChains.h
+++ cfe/trunk/lib/Driver/ToolChains.h
@@ -1249,6 +1249,14 @@
   Tool *buildLinker() const override;
 };
 
+class LLVM_LIBRARY_VISIBILITY Contiki : public Generic_ELF {
+public:
+  Contiki(const Driver , const llvm::Triple ,
+  const llvm::opt::ArgList );
+
+  SanitizerMask getSupportedSanitizers() const override;
+};
+
 } // end namespace toolchains
 } // end namespace driver
 } // end namespace clang
Index: cfe/trunk/lib/Driver/ToolChains.cpp
===
--- cfe/trunk/lib/Driver/ToolChains.cpp
+++ cfe/trunk/lib/Driver/ToolChains.cpp
@@ -5305,3 +5305,14 @@
   Res |= SanitizerKind::Vptr;
   return Res;
 }
+
+Contiki::Contiki(const Driver , const llvm::Triple , const ArgList )
+: Generic_ELF(D, Triple, Args) {}
+
+SanitizerMask Contiki::getSupportedSanitizers() const {
+  const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  if (IsX86)
+Res |= SanitizerKind::SafeStack;
+  return Res;
+}
Index: cfe/trunk/lib/Driver/Driver.cpp

[PATCH] D24958: Test linked to D24957

2016-10-14 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284213: [x86][ms-inline-asm] use of "jmp short" in asm is 
not supported (authored by mzuckerm).

Changed prior to commit:
  https://reviews.llvm.org/D24958?vs=72624=74626#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24958

Files:
  cfe/trunk/test/CodeGen/ms-inline-asm.c


Index: cfe/trunk/test/CodeGen/ms-inline-asm.c
===
--- cfe/trunk/test/CodeGen/ms-inline-asm.c
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c
@@ -634,6 +634,15 @@
   // CHECK: call void asm sideeffect inteldialect "jmp 
{{.*}}__MSASMLABEL_.5__dollar_label$$\0A\09{{.*}}__MSASMLABEL_.5__dollar_label$$:",
 "~{dirflag},~{fpsr},~{flags}"()
 }
 
+void label6(){
+  __asm {
+  jmp short label
+label:
+  }
+  // CHECK-LABEL: define void @label6
+  // CHECK: call void asm sideeffect inteldialect "jmp 
{{.*}}__MSASMLABEL_.6__label\0A\09{{.*}}__MSASMLABEL_.6__label:", 
"~{dirflag},~{fpsr},~{flags}"()
+}
+
 typedef union _LARGE_INTEGER {
   struct {
 unsigned int LowPart;


Index: cfe/trunk/test/CodeGen/ms-inline-asm.c
===
--- cfe/trunk/test/CodeGen/ms-inline-asm.c
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c
@@ -634,6 +634,15 @@
   // CHECK: call void asm sideeffect inteldialect "jmp {{.*}}__MSASMLABEL_.5__dollar_label$$\0A\09{{.*}}__MSASMLABEL_.5__dollar_label$$:", "~{dirflag},~{fpsr},~{flags}"()
 }
 
+void label6(){
+  __asm {
+  jmp short label
+label:
+  }
+  // CHECK-LABEL: define void @label6
+  // CHECK: call void asm sideeffect inteldialect "jmp {{.*}}__MSASMLABEL_.6__label\0A\09{{.*}}__MSASMLABEL_.6__label:", "~{dirflag},~{fpsr},~{flags}"()
+}
+
 typedef union _LARGE_INTEGER {
   struct {
 unsigned int LowPart;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25572: [Coverage] Support for C++17 if initializers

2016-10-14 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284293: [Coverage] Support for C++17 if initializers 
(authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D25572?vs=74559=74753#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25572

Files:
  cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
  cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
  cfe/trunk/test/CoverageMapping/if.c
  cfe/trunk/test/CoverageMapping/if.cpp
  cfe/trunk/test/Profile/cxx-stmt-initializers.cpp

Index: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
===
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
@@ -875,6 +875,9 @@
 
   void VisitIfStmt(const IfStmt *S) {
 extendRegion(S);
+if (S->getInit())
+  Visit(S->getInit());
+
 // Extend into the condition before we propagate through it below - this is
 // needed to handle macros that generate the "if" but not the condition.
 extendRegion(S->getCond());
Index: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
@@ -490,6 +490,8 @@
   void VisitIfStmt(const IfStmt *S) {
 RecordStmtCount(S);
 uint64_t ParentCount = CurrentCount;
+if (S->getInit())
+  Visit(S->getInit());
 Visit(S->getCond());
 
 // Counter tracks the "then" part of an if statement. The count for
Index: cfe/trunk/test/Profile/cxx-stmt-initializers.cpp
===
--- cfe/trunk/test/Profile/cxx-stmt-initializers.cpp
+++ cfe/trunk/test/Profile/cxx-stmt-initializers.cpp
@@ -4,6 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // PGOGEN: @[[SIC:__profc__Z11switch_initv]] = private global [3 x i64] zeroinitializer
+// PGOGEN: @[[IIC:__profc__Z7if_initv]] = private global [3 x i64] zeroinitializer
 
 // Note: We expect counters for the function entry block, the condition in the
 // switch initializer, and the switch successor block.
@@ -15,3 +16,14 @@
   // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 2
   // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 1
 }
+
+// Note: We expect counters for the function entry block, the condition in the
+// if initializer, and the if successor block.
+//
+// CHECK-LABEL: define {{.*}}void @_Z7if_initv()
+// PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 0
+void if_init() {
+  if (int i = true ? 0 : 1; i) {}
+  // PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 2
+  // PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 1
+}
Index: cfe/trunk/test/CoverageMapping/if.cpp
===
--- cfe/trunk/test/CoverageMapping/if.cpp
+++ cfe/trunk/test/CoverageMapping/if.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++1z -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
+
+int nop() { return 0; }
+
+// CHECK-LABEL: _Z3foov:
+void foo() {// CHECK-NEXT: [[@LINE]]:12 -> [[@LINE+5]]:2 = #0
+  if (int j = true ? nop()  // CHECK-NEXT: [[@LINE]]:22 -> [[@LINE]]:27 = #2
+   : nop(); // CHECK-NEXT: [[@LINE]]:22 -> [[@LINE]]:27 = (#0 - #2)
+  j)// CHECK-NEXT: [[@LINE]]:7 -> [[@LINE]]:8 = #0
+++j;// CHECK-NEXT: [[@LINE]]:5 -> [[@LINE]]:8 = #1
+}
+
+// CHECK-LABEL: main:
+int main() {// CHECK: File 0, [[@LINE]]:12 -> {{[0-9]+}}:2 = #0
+  int i = 0;
+// CHECK-NEXT: File 0, [[@LINE+1]]:6 -> [[@LINE+1]]:12 = #0
+  if(i == 0) i = 1; // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE]]:19 = #1
+// CHECK-NEXT: File 0, [[@LINE+1]]:6 -> [[@LINE+1]]:12 = #0
+  if(i == 1)
+i = 2;  // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:10 = #2
+// CHECK-NEXT: File 0, [[@LINE+1]]:6 -> [[@LINE+1]]:12 = #0
+  if(i == 0) { i = 1;   // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+2]]:4 = #3
+i = 2;
+  }
+// CHECK-NEXT: File 0, [[@LINE+1]]:6 -> [[@LINE+1]]:12 = #0
+  if(i != 0) {  // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+2]]:4 = #4
+i = 1;
+  } else {  // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE+2]]:4 = (#0 - #4)
+i = 3;
+  }
+
+  i = i == 0?
+i + 1 : // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:14 = #5
+i + 2;  // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:14 = (#0 - #5)
+// CHECK-NEXT: File 0, [[@LINE+1]]:14 -> [[@LINE+1]]:20 = #6
+  i = i == 0?i + 12:i + 10; // CHECK-NEXT: File 0, [[@LINE]]:21 -> [[@LINE]]:27 = (#0 - #6)
+
+  return 0;
+}

[PATCH] D25539: [Coverage] Support for C++17 switch initializers

2016-10-14 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284292: [Coverage] Support for C++17 switch initializers 
(authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D25539?vs=74552=74752#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25539

Files:
  cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
  cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
  cfe/trunk/test/CoverageMapping/switch.c
  cfe/trunk/test/CoverageMapping/switch.cpp
  cfe/trunk/test/Profile/cxx-stmt-initializers.cpp

Index: cfe/trunk/test/CoverageMapping/switch.cpp
===
--- cfe/trunk/test/CoverageMapping/switch.cpp
+++ cfe/trunk/test/CoverageMapping/switch.cpp
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++1z -triple %itanium_abi_triple -main-file-name switch.cpp %s | FileCheck %s
+
+// CHECK: foo
+void foo(int i) {   // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0
+  switch(i) {
+  case 1:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = #2
+return;
+  case 2:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #3
+break;
+  }
+  int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #1
+}
+
+int nop() { return 0; }
+
+// CHECK: bar
+void bar(int i) {   // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+20]]:2 = #0
+  switch (i)
+;   // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:6 = 0
+
+  switch (i) {  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+16]]:2 = #1
+  }
+
+  switch (i)// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 = #2
+nop();  // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:10 = 0
+
+  switch (i)// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+10]]:2 = #3
+  case 1:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #5
+nop();
+
+  switch (i) {  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:2 = #4
+nop();  // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+2]]:10 = 0
+  case 1:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #7
+nop();
+  }
+  nop();// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #6
+}
+
+// CHECK: baz
+void baz() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+5]]:2 = #0
+  switch (int i = true ? nop()  // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = #2
+   : nop(); // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = (#0 - #2)
+  i) {}
+  nop();// CHECK-NEXT: [[@LINE]]:3 -> [[@LINE+1]]:2 = #1
+}
+
+// CHECK-NEXT: main
+int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+35]]:2 = #0
+  int i = 0;
+  switch(i) {
+  case 0:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+7]]:10 = #2
+i = 1;
+break;
+  case 1:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = #3
+i = 2;
+break;
+  default:  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #4
+break;
+  }
+  switch(i) {   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+23]]:2 = #1
+  case 0:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:10 = #6
+i = 1;
+break;
+  case 1:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = #7
+i = 2;
+  default:  // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = (#7 + #8)
+break;
+  }
+
+  switch(i) {   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 = #5
+  case 1:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:11 = #10
+  case 2:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:11 = (#10 + #11)
+i = 11;
+  case 3:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 = ((#10 + #11) + #12)
+  case 4:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = (((#10 + #11) + #12) + #13)
+i = 99;
+  }
+
+  foo(1);   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:11 = #9
+  bar(1);
+  baz();
+  return 0;
+}
Index: cfe/trunk/test/CoverageMapping/switch.c
===
--- cfe/trunk/test/CoverageMapping/switch.c
+++ cfe/trunk/test/CoverageMapping/switch.c
@@ -1,73 +0,0 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switch.c %s | FileCheck %s
-// CHECK: foo
-void foo(int i) {   // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0
-  switch(i) {
-  case 1:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = #2
-return;
-  case 2:   // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #3
-break;
-  }
-  int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #1
-}
-
-void nop() {}
-
-// CHECK: bar
-void bar(int i) {   // 

[PATCH] D25468: [libcxx] Do not declare the thread api when __external_threading is present

2016-10-14 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284232: [libcxx] Do not declare the thread api when 
__external_threading is present (authored by asiri).

Changed prior to commit:
  https://reviews.llvm.org/D25468?vs=74234=74668#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25468

Files:
  libcxx/trunk/include/__threading_support


Index: libcxx/trunk/include/__threading_support
===
--- libcxx/trunk/include/__threading_support
+++ libcxx/trunk/include/__threading_support
@@ -25,17 +25,16 @@
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #if !defined(__clang__) && (_GNUC_VER < 500)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #elif !defined(__has_include) || __has_include(<__external_threading>)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #endif
 #endif
 
-#if !defined(_LIBCPP_EXTERNAL_THREADING)
+#if !defined(_LIBCPP_HAS_EXTERNAL_THREADING_HEADER)
 #include 
 #include 
-#endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
@@ -242,6 +241,8 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // !_LIBCPP_HAS_EXTERNAL_THREADING_HEADER
+
 #endif // _LIBCPP_HAS_NO_THREADS
 
 #endif // _LIBCPP_THREADING_SUPPORT


Index: libcxx/trunk/include/__threading_support
===
--- libcxx/trunk/include/__threading_support
+++ libcxx/trunk/include/__threading_support
@@ -25,17 +25,16 @@
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #if !defined(__clang__) && (_GNUC_VER < 500)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #elif !defined(__has_include) || __has_include(<__external_threading>)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #endif
 #endif
 
-#if !defined(_LIBCPP_EXTERNAL_THREADING)
+#if !defined(_LIBCPP_HAS_EXTERNAL_THREADING_HEADER)
 #include 
 #include 
-#endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
@@ -242,6 +241,8 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // !_LIBCPP_HAS_EXTERNAL_THREADING_HEADER
+
 #endif // _LIBCPP_HAS_NO_THREADS
 
 #endif // _LIBCPP_THREADING_SUPPORT
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25711: [Basic] unique_ptr-ify SourceManager::MacroArgsCacheMap (NFC)

2016-10-17 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284442: [Basic] unique_ptr-ify 
SourceManager::MacroArgsCacheMap (NFC) (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D25711?vs=74935=74937#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25711

Files:
  cfe/trunk/include/clang/Basic/SourceManager.h
  cfe/trunk/lib/Basic/SourceManager.cpp


Index: cfe/trunk/include/clang/Basic/SourceManager.h
===
--- cfe/trunk/include/clang/Basic/SourceManager.h
+++ cfe/trunk/include/clang/Basic/SourceManager.h
@@ -693,7 +693,8 @@
   /// source location.
   typedef std::map MacroArgsMap;
 
-  mutable llvm::DenseMap MacroArgsCacheMap;
+  mutable llvm::DenseMap
+  MacroArgsCacheMap;
 
   /// \brief The stack of modules being built, which is used to detect
   /// cycles in the module dependency graph as modules are being built, as
@@ -1672,7 +1673,7 @@
   std::pair
   getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
unsigned Offset) const;
-  void computeMacroArgsCache(MacroArgsMap *, FileID FID) const;
+  void computeMacroArgsCache(MacroArgsMap , FileID FID) const;
   void associateFileChunkWithMacroArgExp(MacroArgsMap ,
  FileID FID,
  SourceLocation SpellLoc,
Index: cfe/trunk/lib/Basic/SourceManager.cpp
===
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -386,8 +386,6 @@
   ContentCacheAlloc.Deallocate(I->second);
 }
   }
-
-  llvm::DeleteContainerSeconds(MacroArgsCacheMap);
 }
 
 void SourceManager::clearIDTables() {
@@ -1784,13 +1782,10 @@
 /// 0   -> SourceLocation()
 /// 100 -> Expanded macro arg location
 /// 110 -> SourceLocation()
-void SourceManager::computeMacroArgsCache(MacroArgsMap *,
+void SourceManager::computeMacroArgsCache(MacroArgsMap ,
   FileID FID) const {
   assert(FID.isValid());
-  assert(!CachePtr);
 
-  CachePtr = new MacroArgsMap();
-  MacroArgsMap  = *CachePtr;
   // Initially no macro argument chunk is present.
   MacroArgsCache.insert(std::make_pair(0, SourceLocation()));
 
@@ -1940,9 +1935,11 @@
   if (FID.isInvalid())
 return Loc;
 
-  MacroArgsMap * = MacroArgsCacheMap[FID];
-  if (!MacroArgsCache)
-computeMacroArgsCache(MacroArgsCache, FID);
+  std::unique_ptr  = MacroArgsCacheMap[FID];
+  if (!MacroArgsCache) {
+MacroArgsCache = llvm::make_unique();
+computeMacroArgsCache(*MacroArgsCache.get(), FID);
+  }
 
   assert(!MacroArgsCache->empty());
   MacroArgsMap::iterator I = MacroArgsCache->upper_bound(Offset);


Index: cfe/trunk/include/clang/Basic/SourceManager.h
===
--- cfe/trunk/include/clang/Basic/SourceManager.h
+++ cfe/trunk/include/clang/Basic/SourceManager.h
@@ -693,7 +693,8 @@
   /// source location.
   typedef std::map MacroArgsMap;
 
-  mutable llvm::DenseMap MacroArgsCacheMap;
+  mutable llvm::DenseMap
+  MacroArgsCacheMap;
 
   /// \brief The stack of modules being built, which is used to detect
   /// cycles in the module dependency graph as modules are being built, as
@@ -1672,7 +1673,7 @@
   std::pair
   getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
unsigned Offset) const;
-  void computeMacroArgsCache(MacroArgsMap *, FileID FID) const;
+  void computeMacroArgsCache(MacroArgsMap , FileID FID) const;
   void associateFileChunkWithMacroArgExp(MacroArgsMap ,
  FileID FID,
  SourceLocation SpellLoc,
Index: cfe/trunk/lib/Basic/SourceManager.cpp
===
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -386,8 +386,6 @@
   ContentCacheAlloc.Deallocate(I->second);
 }
   }
-
-  llvm::DeleteContainerSeconds(MacroArgsCacheMap);
 }
 
 void SourceManager::clearIDTables() {
@@ -1784,13 +1782,10 @@
 /// 0   -> SourceLocation()
 /// 100 -> Expanded macro arg location
 /// 110 -> SourceLocation()
-void SourceManager::computeMacroArgsCache(MacroArgsMap *,
+void SourceManager::computeMacroArgsCache(MacroArgsMap ,
   FileID FID) const {
   assert(FID.isValid());
-  assert(!CachePtr);
 
-  CachePtr = new MacroArgsMap();
-  MacroArgsMap  = *CachePtr;
   // Initially no macro argument chunk is present.
   MacroArgsCache.insert(std::make_pair(0, SourceLocation()));
 
@@ -1940,9 +1935,11 @@
   if (FID.isInvalid())
 

[PATCH] D25936: Fix format string for err_os_log_argument_to_big (currently unused)

2016-10-25 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285065: Fix diagnostic format string for 
err_os_log_argument_to_big (authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D25936?vs=75685=75687#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25936

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/test/SemaObjC/format-strings-oslog.m


Index: cfe/trunk/test/SemaObjC/format-strings-oslog.m
===
--- cfe/trunk/test/SemaObjC/format-strings-oslog.m
+++ cfe/trunk/test/SemaObjC/format-strings-oslog.m
@@ -36,6 +36,9 @@
   wchar_t wcs[] = {'a', 0};
   __builtin_os_log_format(buf, "%S", wcs);
   printf("%S", wcs);
+
+  struct { char data[0x100]; } toobig;
+  __builtin_os_log_format(buf, "%s", toobig); // expected-error {{os_log() 
argument 2 is too big (256 bytes, max 255)}}
 }
 
 // Test os_log_format primitive with ObjC string literal format argument.
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7570,7 +7570,7 @@
 def err_os_log_format_not_string_constant : Error<
   "os_log() format argument is not a string constant">;
 def err_os_log_argument_too_big : Error<
-  "os_log() argument %d is too big (%d bytes, max %d)">;
+  "os_log() argument %0 is too big (%1 bytes, max %2)">;
 def warn_os_log_format_narg : Error<
  "os_log() '%%n' format specifier is not allowed">, DefaultError;
 


Index: cfe/trunk/test/SemaObjC/format-strings-oslog.m
===
--- cfe/trunk/test/SemaObjC/format-strings-oslog.m
+++ cfe/trunk/test/SemaObjC/format-strings-oslog.m
@@ -36,6 +36,9 @@
   wchar_t wcs[] = {'a', 0};
   __builtin_os_log_format(buf, "%S", wcs);
   printf("%S", wcs);
+
+  struct { char data[0x100]; } toobig;
+  __builtin_os_log_format(buf, "%s", toobig); // expected-error {{os_log() argument 2 is too big (256 bytes, max 255)}}
 }
 
 // Test os_log_format primitive with ObjC string literal format argument.
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7570,7 +7570,7 @@
 def err_os_log_format_not_string_constant : Error<
   "os_log() format argument is not a string constant">;
 def err_os_log_argument_too_big : Error<
-  "os_log() argument %d is too big (%d bytes, max %d)">;
+  "os_log() argument %0 is too big (%1 bytes, max %2)">;
 def warn_os_log_format_narg : Error<
  "os_log() '%%n' format specifier is not allowed">, DefaultError;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25813: [CodeGen] Devirtualize calls to methods marked final in a derived class

2016-10-20 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284766: [CodeGen] Devirtualize calls to methods marked final 
in a derived class (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D25813?vs=75266=75331#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25813

Files:
  cfe/trunk/lib/CodeGen/CGClass.cpp
  cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  cfe/trunk/test/CodeGenCXX/ubsan-devirtualized-calls.cpp

Index: cfe/trunk/lib/CodeGen/CGClass.cpp
===
--- cfe/trunk/lib/CodeGen/CGClass.cpp
+++ cfe/trunk/lib/CodeGen/CGClass.cpp
@@ -2873,6 +2873,11 @@
   if (getLangOpts().AppleKext)
 return false;
 
+  // If the member function is marked 'final', we know that it can't be
+  // overridden and can therefore devirtualize it.
+  if (MD->hasAttr())
+return true;
+
   // If the most derived class is marked final, we know that no subclass can
   // override this member function and so we can devirtualize it. For example:
   //
@@ -2883,14 +2888,17 @@
   //   b->f();
   // }
   //
-  const CXXRecordDecl *MostDerivedClassDecl = Base->getBestDynamicClassType();
-  if (MostDerivedClassDecl->hasAttr())
-return true;
+  if (const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType()) {
+if (BestDynamicDecl->hasAttr())
+  return true;
 
-  // If the member function is marked 'final', we know that it can't be
-  // overridden and can therefore devirtualize it.
-  if (MD->hasAttr())
-return true;
+// There may be a method corresponding to MD in a derived class. If that
+// method is marked final, we can devirtualize it.
+const CXXMethodDecl *DevirtualizedMethod =
+MD->getCorrespondingMethodInClass(BestDynamicDecl);
+if (DevirtualizedMethod->hasAttr())
+  return true;
+  }
 
   // Similarly, if the class itself is marked 'final' it can't be overridden
   // and we can therefore devirtualize the member function call.
Index: cfe/trunk/test/CodeGenCXX/ubsan-devirtualized-calls.cpp
===
--- cfe/trunk/test/CodeGenCXX/ubsan-devirtualized-calls.cpp
+++ cfe/trunk/test/CodeGenCXX/ubsan-devirtualized-calls.cpp
@@ -16,9 +16,6 @@
   void f1() override {}
 };
 
-// PR13127 documents some missed devirtualization opportunities, including
-// devirt for methods marked 'final'. We can enable the checks marked 'PR13127'
-// if we implement this in the frontend.
 struct Derived3 : Base1 {
   void f1() override /* nofinal */ {}
 };
@@ -30,10 +27,10 @@
 // CHECK: [[UBSAN_TI_DERIVED1_1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived1 to i8*
 // CHECK: [[UBSAN_TI_DERIVED2_1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived2 to i8*
 // CHECK: [[UBSAN_TI_DERIVED2_2:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived2 to i8*
-// PR13127: [[UBSAN_TI_DERIVED3:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived3 to i8*
-// PR13127: [[UBSAN_TI_BASE1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI5Base1 to i8*
-// PR13127: [[UBSAN_TI_DERIVED4_1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived4 to i8*
-// PR13127: [[UBSAN_TI_DERIVED4_2:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived4 to i8*
+// CHECK: [[UBSAN_TI_DERIVED3:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived3 to i8*
+// CHECK: [[UBSAN_TI_BASE1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI5Base1 to i8*
+// CHECK: [[UBSAN_TI_DERIVED4_1:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived4 to i8*
+// CHECK: [[UBSAN_TI_DERIVED4_2:@[0-9]+]] = private unnamed_addr global {{.*}} i8* bitcast {{.*}} @_ZTI8Derived4 to i8*
 
 // CHECK-LABEL: define void @_Z2t1v
 void t1() {
@@ -59,26 +56,26 @@
   // CHECK-NEXT: call void @__ubsan_handle_dynamic_type_cache{{[_a-z]*}}({{.*}} [[UBSAN_TI_DERIVED2_2]] {{.*}}, i{{[0-9]+}} %[[D2_2]]
 }
 
-// PR13127-LABEL: define void @_Z2t4v
+// CHECK-LABEL: define void @_Z2t4v
 void t4() {
   Base1 p;
   Derived3 *badp = static_cast(); //< Check that  isa Derived3.
-  // PR13127: %[[P1:[0-9]+]] = ptrtoint %struct.Derived3* {{%[0-9]+}} to i{{[0-9]+}}, !nosanitize
-  // PR13127-NEXT: call void @__ubsan_handle_dynamic_type_cache{{[_a-z]*}}({{.*}} [[UBSAN_TI_DERIVED3]] {{.*}}, i{{[0-9]+}} %[[P1]]
+  // CHECK: %[[P1:[0-9]+]] = ptrtoint %struct.Derived3* {{%[0-9]+}} to i{{[0-9]+}}, !nosanitize
+  // CHECK-NEXT: call void @__ubsan_handle_dynamic_type_cache{{[_a-z]*}}({{.*}} [[UBSAN_TI_DERIVED3]] {{.*}}, i{{[0-9]+}} %[[P1]]
 
   static_cast(badp)->f1(); //< No devirt, test 'badp isa Base1'.
-  // PR13127: %[[BADP1:[0-9]+]] = ptrtoint %struct.Base1* {{%[0-9]+}} to i{{[0-9]+}}, !nosanitize
-  // PR13127-NEXT: call void 

[PATCH] D25806: Module: correctly set the module file kind when emitting diagnostics for file_modified

2016-10-21 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284899: Module: correctly set the module file kind when 
emitting file_modified. (authored by mren).

Changed prior to commit:
  https://reviews.llvm.org/D25806?vs=75326=75510#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25806

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/test/Modules/module-file-modified.c


Index: cfe/trunk/lib/Serialization/ASTReader.cpp
===
--- cfe/trunk/lib/Serialization/ASTReader.cpp
+++ cfe/trunk/lib/Serialization/ASTReader.cpp
@@ -1983,6 +1983,7 @@
   return R;
 }
 
+static unsigned moduleKindForDiagnostic(ModuleKind Kind);
 InputFile ASTReader::getInputFile(ModuleFile , unsigned ID, bool Complain) {
   // If this ID is bogus, just return an empty input file.
   if (ID == 0 || ID > F.InputFilesLoaded.size())
@@ -2079,7 +2080,13 @@
 
   // The top-level PCH is stale.
   StringRef TopLevelPCHName(ImportStack.back()->FileName);
-  Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  unsigned DiagnosticKind = 
moduleKindForDiagnostic(ImportStack.back()->Kind);
+  if (DiagnosticKind == 0)
+Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  else if (DiagnosticKind == 1)
+Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
+  else
+Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
 
   // Print the import stack.
   if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
Index: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -21,6 +21,12 @@
 def err_fe_pch_file_modified : Error<
 "file '%0' has been modified since the precompiled header '%1' was built">,
 DefaultFatal;
+def err_fe_module_file_modified : Error<
+"file '%0' has been modified since the module file '%1' was built">,
+DefaultFatal;
+def err_fe_ast_file_modified : Error<
+"file '%0' has been modified since the AST file '%1' was built">,
+DefaultFatal;
 def err_fe_pch_file_overridden : Error<
 "file '%0' from the precompiled header has been overridden">;
 def note_pch_required_by : Note<"'%0' required by '%1'">;
Index: cfe/trunk/test/Modules/module-file-modified.c
===
--- cfe/trunk/test/Modules/module-file-modified.c
+++ cfe/trunk/test/Modules/module-file-modified.c
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo 'int foo = 0;' > %t/a.h
+// RUN: echo 'module A { header "a.h" }' > %t/m.modulemap
+// RUN: %clang_cc1 -fmodules -emit-module -fmodule-name=A -x c %t/m.modulemap 
-o %t/m.pcm
+// RUN: echo 'int bar;' > %t/a.h
+// RUN: not %clang_cc1 -fmodules -fmodule-file=%t/m.pcm 
-fmodule-map-file=%t/m.modulemap -x c %s -I%t -fsyntax-only 2>&1 | FileCheck %s
+#include "a.h"
+int foo = 0; // redefinition of 'foo'
+// CHECK: fatal error: file {{.*}} has been modified since the module file 
{{.*}} was built
+// REQUIRES: shell


Index: cfe/trunk/lib/Serialization/ASTReader.cpp
===
--- cfe/trunk/lib/Serialization/ASTReader.cpp
+++ cfe/trunk/lib/Serialization/ASTReader.cpp
@@ -1983,6 +1983,7 @@
   return R;
 }
 
+static unsigned moduleKindForDiagnostic(ModuleKind Kind);
 InputFile ASTReader::getInputFile(ModuleFile , unsigned ID, bool Complain) {
   // If this ID is bogus, just return an empty input file.
   if (ID == 0 || ID > F.InputFilesLoaded.size())
@@ -2079,7 +2080,13 @@
 
   // The top-level PCH is stale.
   StringRef TopLevelPCHName(ImportStack.back()->FileName);
-  Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind);
+  if (DiagnosticKind == 0)
+Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  else if (DiagnosticKind == 1)
+Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
+  else
+Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
 
   // Print the import stack.
   if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
Index: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -21,6 +21,12 @@
 def err_fe_pch_file_modified : Error<
 "file '%0' has been modified since the precompiled header '%1' was built">,
 DefaultFatal;
+def 

[PATCH] D20811: [analyzer] Model some library functions

2016-10-24 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284960: [analyzer] Add StdLibraryFunctions checker. 
(authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D20811?vs=75446=75560#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D20811

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
  cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  cfe/trunk/test/Analysis/std-c-library-functions.c
  cfe/trunk/test/Analysis/std-c-library-functions.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -0,0 +1,943 @@
+//=== StdLibraryFunctionsChecker.cpp - Model standard functions -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This checker improves modeling of a few simple library functions.
+// It does not generate warnings.
+//
+// This checker provides a specification format - `FunctionSummaryTy' - and
+// contains descriptions of some library functions in this format. Each
+// specification contains a list of branches for splitting the program state
+// upon call, and range constraints on argument and return-value symbols that
+// are satisfied on each branch. This spec can be expanded to include more
+// items, like external effects of the function.
+//
+// The main difference between this approach and the body farms technique is
+// in more explicit control over how many branches are produced. For example,
+// consider standard C function `ispunct(int x)', which returns a non-zero value
+// iff `x' is a punctuation character, that is, when `x' is in range
+//   ['!', '/']   [':', '@']  U  ['[', '\`']  U  ['{', '~'].
+// `FunctionSummaryTy' provides only two branches for this function. However,
+// any attempt to describe this range with if-statements in the body farm
+// would result in many more branches. Because each branch needs to be analyzed
+// independently, this significantly reduces performance. Additionally,
+// once we consider a branch on which `x' is in range, say, ['!', '/'],
+// we assume that such branch is an important separate path through the program,
+// which may lead to false positives because considering this particular path
+// was not consciously intended, and therefore it might have been unreachable.
+//
+// This checker uses eval::Call for modeling "pure" functions, for which
+// their `FunctionSummaryTy' is a precise model. This avoids unnecessary
+// invalidation passes. Conflicts with other checkers are unlikely because
+// if the function has no other effects, other checkers would probably never
+// want to improve upon the modeling done by this checker.
+//
+// Non-"pure" functions, for which only partial improvement over the default
+// behavior is expected, are modeled via check::PostCall, non-intrusively.
+//
+// The following standard C functions are currently supported:
+//
+//   fgetc  getline   isdigit   isupper
+//   fread  isalnum   isgraph   isxdigit
+//   fwrite isalpha   islower   read
+//   getc   isascii   isprint   write
+//   getcharisblank   ispunct
+//   getdelim   iscntrl   isspace
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+
+using namespace clang;
+using namespace clang::ento;
+
+namespace {
+class StdLibraryFunctionsChecker : public Checker {
+  /// Below is a series of typedefs necessary to define function specs.
+  /// We avoid nesting types here because each additional qualifier
+  /// would need to be repeated in every function spec.
+  struct FunctionSummaryTy;
+
+  /// Specify how much the analyzer engine should entrust modeling this function
+  /// to us. If he doesn't, he performs additional invalidations.
+  enum InvalidationKindTy { NoEvalCall, EvalCallAsPure };
+
+  /// A pair of ValueRangeKindTy and IntRangeVectorTy would describe a range
+  /// imposed on a particular argument or return value symbol.
+  ///
+  /// Given a range, should the argument stay inside or outside this range?
+  /// The special `ComparesToArgument' value indicates that we should
+  /// impose a constraint that involves other argument or return value symbols.
+  enum 

[PATCH] D26328: [ASTImporter] Added ability to import AtomicType nodes

2016-11-23 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287763: [ASTImporter] Added ability to import AtomicType 
nodes (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D26328?vs=76976=79080#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26328

Files:
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/unittests/AST/ASTImporterTest.cpp


Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -39,6 +39,7 @@
 
 // Importing types
 QualType VisitType(const Type *T);
+QualType VisitAtomicType(const AtomicType *T);
 QualType VisitBuiltinType(const BuiltinType *T);
 QualType VisitDecayedType(const DecayedType *T);
 QualType VisitComplexType(const ComplexType *T);
@@ -1600,6 +1601,14 @@
   return QualType();
 }
 
+QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
+  QualType UnderlyingType = Importer.Import(T->getValueType());
+  if(UnderlyingType.isNull())
+return QualType();
+
+  return Importer.getToContext().getAtomicType(UnderlyingType);
+}
+
 QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
   switch (T->getKind()) {
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
Index: cfe/trunk/unittests/AST/ASTImporterTest.cpp
===
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp
@@ -474,5 +474,20 @@
 }
 
 
+TEST(ImportType, ImportAtomicType) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { typedef _Atomic(int) a_int; }",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ declStmt(
+   has(
+ typedefDecl(
+   has(atomicType()));
+}
+
+
 } // end namespace ast_matchers
 } // end namespace clang


Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -39,6 +39,7 @@
 
 // Importing types
 QualType VisitType(const Type *T);
+QualType VisitAtomicType(const AtomicType *T);
 QualType VisitBuiltinType(const BuiltinType *T);
 QualType VisitDecayedType(const DecayedType *T);
 QualType VisitComplexType(const ComplexType *T);
@@ -1600,6 +1601,14 @@
   return QualType();
 }
 
+QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
+  QualType UnderlyingType = Importer.Import(T->getValueType());
+  if(UnderlyingType.isNull())
+return QualType();
+
+  return Importer.getToContext().getAtomicType(UnderlyingType);
+}
+
 QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
   switch (T->getKind()) {
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
Index: cfe/trunk/unittests/AST/ASTImporterTest.cpp
===
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp
@@ -474,5 +474,20 @@
 }
 
 
+TEST(ImportType, ImportAtomicType) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { typedef _Atomic(int) a_int; }",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ declStmt(
+   has(
+ typedefDecl(
+   has(atomicType()));
+}
+
+
 } // end namespace ast_matchers
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26442: [analyzer] Fix crash on getSVal: handle case of CompoundVal

2016-11-21 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287618: [analyzer] Fix a crash on accessing a field within a 
literal-initialized union. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D26442?vs=77316=78826#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26442

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
  cfe/trunk/test/Analysis/uninit-vals-union.c


Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1674,7 +1674,8 @@
 
 // Lazy bindings are usually handled through getExistingLazyBinding().
 // We should unify these two code paths at some point.
-if (val.getAs())
+if (val.getAs() ||
+val.getAs())
   return val;
 
 llvm_unreachable("Unknown default value");
Index: cfe/trunk/test/Analysis/uninit-vals-union.c
===
--- cfe/trunk/test/Analysis/uninit-vals-union.c
+++ cfe/trunk/test/Analysis/uninit-vals-union.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core.builtin 
-analyzer-store=region -verify -Wno-unused %s
+
+typedef union {
+  int y;
+} U;
+
+typedef struct { int x; } A;
+
+void foo() {
+  U u = {};
+  A *a =  // expected-warning{{incompatible pointer types}}
+  a->x;  // no-crash
+}


Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1674,7 +1674,8 @@
 
 // Lazy bindings are usually handled through getExistingLazyBinding().
 // We should unify these two code paths at some point.
-if (val.getAs())
+if (val.getAs() ||
+val.getAs())
   return val;
 
 llvm_unreachable("Unknown default value");
Index: cfe/trunk/test/Analysis/uninit-vals-union.c
===
--- cfe/trunk/test/Analysis/uninit-vals-union.c
+++ cfe/trunk/test/Analysis/uninit-vals-union.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core.builtin -analyzer-store=region -verify -Wno-unused %s
+
+typedef union {
+  int y;
+} U;
+
+typedef struct { int x; } A;
+
+void foo() {
+  U u = {};
+  A *a =  // expected-warning{{incompatible pointer types}}
+  a->x;  // no-crash
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26759: Remove unused check::RegionChanges::wantsRegionChangeUpdate callback

2016-11-16 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287175: [analyzer] Remove unused 
check::RegionChanges::wantsRegionChangeUpdate callback (authored by zaks).

Changed prior to commit:
  https://reviews.llvm.org/D26759?vs=78249=78271#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26759

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
  cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp

Index: cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
@@ -325,20 +325,13 @@
 return ((const CHECKER *)checker)->checkRegionChanges(state, invalidated,
   Explicits, Regions, Call);
   }
-  template 
-  static bool _wantsRegionChangeUpdate(void *checker,
-   ProgramStateRef state) {
-return ((const CHECKER *)checker)->wantsRegionChangeUpdate(state);
-  }
 
 public:
   template 
   static void _register(CHECKER *checker, CheckerManager ) {
 mgr._registerForRegionChanges(
   CheckerManager::CheckRegionChangesFunc(checker,
- _checkRegionChanges),
-  CheckerManager::WantsRegionChangeUpdateFunc(checker,
-_wantsRegionChangeUpdate));
+ _checkRegionChanges));
   }
 };
 
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -286,10 +286,6 @@
   ProgramStateRef processAssume(ProgramStateRef state, SVal cond,
 bool assumption) override;
 
-  /// wantsRegionChangeUpdate - Called by ProgramStateManager to determine if a
-  ///  region change should trigger a processRegionChanges update.
-  bool wantsRegionChangeUpdate(ProgramStateRef state) override;
-
   /// processRegionChanges - Called by ProgramStateManager whenever a change is made
   ///  to the store. Used to update checkers that track region values.
   ProgramStateRef 
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
@@ -124,10 +124,6 @@
   virtual ProgramStateRef processAssume(ProgramStateRef state,
SVal cond, bool assumption) = 0;
 
-  /// wantsRegionChangeUpdate - Called by ProgramStateManager to determine if a
-  ///  region change should trigger a processRegionChanges update.
-  virtual bool wantsRegionChangeUpdate(ProgramStateRef state) = 0;
-
   /// processRegionChanges - Called by ProgramStateManager whenever a change is
   /// made to the store. Used to update checkers that track region values.
   virtual ProgramStateRef 
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -322,9 +322,6 @@
  ExprEngine ,
  ProgramPoint::Kind K);
 
-  /// \brief True if at least one checker wants to check region changes.
-  bool wantsRegionChangeUpdate(ProgramStateRef state);
-
   /// \brief Run checkers for region changes.
   ///
   /// This corresponds to the check::RegionChanges callback.
@@ -452,8 +449,6 @@
 const CallEvent *Call)>
   CheckRegionChangesFunc;
   
-  typedef CheckerFn WantsRegionChangeUpdateFunc;
-
   typedef CheckerFn DeadSymbolsCheckers;
 
-  struct RegionChangesCheckerInfo {
-CheckRegionChangesFunc CheckFn;
-WantsRegionChangeUpdateFunc WantUpdateFn;
-  };
-  std::vector RegionChangesCheckers;
+  std::vector RegionChangesCheckers;
 
   std::vector PointerEscapeCheckers;
 
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -262,10 +262,6 @@
   

[PATCH] D26752: [include-fixer] Refactor include fixer to be usable as a plugin

2016-11-17 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287228: [include-fixer] Refactor include fixer to be usable 
as a plugin (authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D26752?vs=78354=78366#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26752

Files:
  clang-tools-extra/trunk/include-fixer/CMakeLists.txt
  clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
  clang-tools-extra/trunk/include-fixer/IncludeFixer.h
  clang-tools-extra/trunk/include-fixer/plugin/CMakeLists.txt
  clang-tools-extra/trunk/include-fixer/plugin/IncludeFixerPlugin.cpp

Index: clang-tools-extra/trunk/include-fixer/IncludeFixer.h
===
--- clang-tools-extra/trunk/include-fixer/IncludeFixer.h
+++ clang-tools-extra/trunk/include-fixer/IncludeFixer.h
@@ -13,6 +13,7 @@
 #include "IncludeFixerContext.h"
 #include "SymbolIndexManager.h"
 #include "clang/Format/Format.h"
+#include "clang/Sema/ExternalSemaSource.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Tooling.h"
 #include 
@@ -80,6 +81,70 @@
 const format::FormatStyle  = format::getLLVMStyle(),
 bool AddQualifiers = true);
 
+/// Handles callbacks from sema, does the include lookup and turns it into an
+/// IncludeFixerContext.
+class IncludeFixerSemaSource : public clang::ExternalSemaSource {
+public:
+  explicit IncludeFixerSemaSource(SymbolIndexManager ,
+  bool MinimizeIncludePaths,
+  bool GenerateDiagnostics)
+  : SymbolIndexMgr(SymbolIndexMgr),
+MinimizeIncludePaths(MinimizeIncludePaths),
+GenerateDiagnostics(GenerateDiagnostics) {}
+
+  void setCompilerInstance(CompilerInstance *CI) { this->CI = CI; }
+  void setFilePath(StringRef FilePath) { this->FilePath = FilePath; }
+
+  /// Callback for incomplete types. If we encounter a forward declaration we
+  /// have the fully qualified name ready. Just query that.
+  bool MaybeDiagnoseMissingCompleteType(clang::SourceLocation Loc,
+clang::QualType T) override;
+
+  /// Callback for unknown identifiers. Try to piece together as much
+  /// qualification as we can get and do a query.
+  clang::TypoCorrection CorrectTypo(const DeclarationNameInfo ,
+int LookupKind, Scope *S, CXXScopeSpec *SS,
+CorrectionCandidateCallback ,
+DeclContext *MemberContext,
+bool EnteringContext,
+const ObjCObjectPointerType *OPT) override;
+
+  /// Get the minimal include for a given path.
+  std::string minimizeInclude(StringRef Include,
+  const clang::SourceManager ,
+  clang::HeaderSearch ) const;
+
+  /// Get the include fixer context for the queried symbol.
+  IncludeFixerContext
+  getIncludeFixerContext(const clang::SourceManager ,
+ clang::HeaderSearch ) const;
+
+private:
+  /// Query the database for a given identifier.
+  bool query(StringRef Query, StringRef ScopedQualifiers, tooling::Range Range);
+
+  CompilerInstance *CI;
+
+  /// The client to use to find cross-references.
+  SymbolIndexManager 
+
+  /// The information of the symbols being queried.
+  std::vector QuerySymbolInfos;
+
+  /// All symbol candidates which match QuerySymbol. We only include the first
+  /// discovered identifier to avoid getting caught in results from error
+  /// recovery.
+  std::vector MatchedSymbols;
+
+  /// The file path to the file being processed.
+  std::string FilePath;
+
+  /// Whether we should use the smallest possible include path.
+  bool MinimizeIncludePaths = true;
+
+  /// Whether we should generate diagnostics with fixits for missing symbols.
+  bool GenerateDiagnostics = false;
+};
 } // namespace include_fixer
 } // namespace clang
 
Index: clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
===
--- clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
+++ clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
@@ -13,7 +13,6 @@
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Parse/ParseAST.h"
-#include "clang/Sema/ExternalSemaSource.h"
 #include "clang/Sema/Sema.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -25,19 +24,17 @@
 namespace clang {
 namespace include_fixer {
 namespace {
-
 /// Manages the parse, gathers include suggestions.
-class Action : public clang::ASTFrontendAction,
-   public clang::ExternalSemaSource {
+class Action : public clang::ASTFrontendAction {
 public:
   explicit Action(SymbolIndexManager , bool MinimizeIncludePaths)
-  : SymbolIndexMgr(SymbolIndexMgr),
-MinimizeIncludePaths(MinimizeIncludePaths) {}

[PATCH] D26745: [Frontend] Allow attaching an external sema source to compiler instance and extra diags to TypoCorrections

2016-11-16 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287128: [Frontend] Allow attaching an external sema source 
to compiler instance and… (authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D26745?vs=78179=78213#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26745

Files:
  cfe/trunk/include/clang/Frontend/CompilerInstance.h
  cfe/trunk/include/clang/Sema/TypoCorrection.h
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/lib/Sema/SemaLookup.cpp
  cfe/trunk/unittests/Frontend/FrontendActionTest.cpp

Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp
@@ -538,6 +538,11 @@
   CodeCompleteConsumer *CompletionConsumer) {
   TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(),
  TUKind, CompletionConsumer));
+  // Attach the external sema source if there is any.
+  if (ExternalSemaSrc) {
+TheSema->addExternalSource(ExternalSemaSrc.get());
+ExternalSemaSrc->InitializeSema(*TheSema);
+  }
 }
 
 // Output Files
@@ -1820,3 +1825,8 @@
   return false;
 }
 void CompilerInstance::resetAndLeakSema() { BuryPointer(takeSema()); }
+
+void CompilerInstance::setExternalSemaSource(
+IntrusiveRefCntPtr ESS) {
+  ExternalSemaSrc = std::move(ESS);
+}
Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -5082,6 +5082,10 @@
   if (PrevNote.getDiagID() && ChosenDecl)
 Diag(ChosenDecl->getLocation(), PrevNote)
   << CorrectedQuotedStr << (ErrorRecovery ? FixItHint() : FixTypo);
+
+  // Add any extra diagnostics.
+  for (const PartialDiagnostic  : Correction.getExtraDiagnostics())
+Diag(Correction.getCorrectionRange().getBegin(), PD);
 }
 
 TypoExpr *Sema::createDelayedTypo(std::unique_ptr TCC,
Index: cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
===
--- cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
+++ cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
@@ -13,6 +13,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Sema/Sema.h"
@@ -192,4 +193,66 @@
   ASSERT_TRUE(TestAction.SeenEnd);
 }
 
+class TypoExternalSemaSource : public ExternalSemaSource {
+  CompilerInstance 
+
+public:
+  TypoExternalSemaSource(CompilerInstance ) : CI(CI) {}
+
+  TypoCorrection CorrectTypo(const DeclarationNameInfo , int LookupKind,
+ Scope *S, CXXScopeSpec *SS,
+ CorrectionCandidateCallback ,
+ DeclContext *MemberContext, bool EnteringContext,
+ const ObjCObjectPointerType *OPT) override {
+// Generate a fake typo correction with one attached note.
+ASTContext  = CI.getASTContext();
+TypoCorrection TC(DeclarationName(("moo")));
+unsigned DiagID = Ctx.getDiagnostics().getCustomDiagID(
+DiagnosticsEngine::Note, "This is a note");
+TC.addExtraDiagnostic(PartialDiagnostic(DiagID, Ctx.getDiagAllocator()));
+return TC;
+  }
+};
+
+struct TypoDiagnosticConsumer : public DiagnosticConsumer {
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic ) override {
+// Capture errors and notes. There should be one of each.
+if (DiagLevel == DiagnosticsEngine::Error) {
+  assert(Error.empty());
+  Info.FormatDiagnostic(Error);
+} else {
+  assert(Note.empty());
+  Info.FormatDiagnostic(Note);
+}
+  }
+  SmallString<32> Error;
+  SmallString<32> Note;
+};
+
+TEST(ASTFrontendAction, ExternalSemaSource) {
+  auto *Invocation = new CompilerInvocation;
+  Invocation->getLangOpts()->CPlusPlus = true;
+  Invocation->getPreprocessorOpts().addRemappedFile(
+  "test.cc", MemoryBuffer::getMemBuffer("void fooo();\n"
+"int main() { foo(); }")
+ .release());
+  Invocation->getFrontendOpts().Inputs.push_back(
+  FrontendInputFile("test.cc", IK_CXX));
+  Invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly;
+  Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
+  CompilerInstance Compiler;
+  Compiler.setInvocation(Invocation);
+  auto *TDC = new TypoDiagnosticConsumer;
+  Compiler.createDiagnostics(TDC, /*ShouldOwnClient=*/true);
+  Compiler.setExternalSemaSource(new TypoExternalSemaSource(Compiler));
+
+  SyntaxOnlyAction TestAction;
+  ASSERT_TRUE(Compiler.ExecuteAction(TestAction));
+  

[PATCH] D26019: [AVX-512] Use scalar vfmsub/vfnmsub mask3 intrinsics instead of inverting the mask argument of a vfmadd intrinsic.

2016-11-12 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL286733: [AVX-512] Use scalar vfmsub/vfnmsub mask3 intrinsics 
instead of inverting the… (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D26019?vs=75978=77729#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26019

Files:
  cfe/trunk/include/clang/Basic/BuiltinsX86.def
  cfe/trunk/lib/Headers/avx512fintrin.h
  cfe/trunk/test/CodeGen/avx512f-builtins.c

Index: cfe/trunk/include/clang/Basic/BuiltinsX86.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def
@@ -1743,6 +1743,10 @@
 TARGET_BUILTIN(__builtin_ia32_vfmaddsd3_mask,  "V2dV2dV2dV2dUcIi", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_vfmaddsd3_maskz, "V2dV2dV2dV2dUcIi", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_vfmaddsd3_mask3, "V2dV2dV2dV2dUcIi", "", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_vfmsubsd3_mask3, "V2dV2dV2dV2dUcIi", "", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_vfmsubss3_mask3, "V4fV4fV4fV4fUcIi", "", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_vfnmsubsd3_mask3, "V2dV2dV2dV2dUcIi", "", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_vfnmsubss3_mask3, "V4fV4fV4fV4fUcIi", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_permvarhi512_mask, "V32sV32sV32sV32sUi","","avx512bw")
 TARGET_BUILTIN(__builtin_ia32_permvardf512_mask, "V8dV8dV8LLiV8dUc","","avx512f")
 TARGET_BUILTIN(__builtin_ia32_permvardi512_mask, "V8LLiV8LLiV8LLiV8LLiUc","","avx512f")
Index: cfe/trunk/test/CodeGen/avx512f-builtins.c
===
--- cfe/trunk/test/CodeGen/avx512f-builtins.c
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c
@@ -5813,13 +5813,13 @@
 
 __m128 test_mm_mask3_fmsub_ss(__m128 __W, __m128 __X, __m128 __Y, __mmask8 __U){
   // CHECK-LABEL: @test_mm_mask3_fmsub_ss
-  // CHECK: @llvm.x86.avx512.mask3.vfmadd.ss
+  // CHECK: @llvm.x86.avx512.mask3.vfmsub.ss
   return _mm_mask3_fmsub_ss(__W, __X, __Y, __U);
 }
 
 __m128 test_mm_mask3_fmsub_round_ss(__m128 __W, __m128 __X, __m128 __Y, __mmask8 __U){
   // CHECK-LABEL: @test_mm_mask3_fmsub_round_ss
-  // CHECK: @llvm.x86.avx512.mask3.vfmadd.ss
+  // CHECK: @llvm.x86.avx512.mask3.vfmsub.ss
   return _mm_mask3_fmsub_round_ss(__W, __X, __Y, __U, _MM_FROUND_CUR_DIRECTION);
 }
 
@@ -5885,13 +5885,13 @@
 
 __m128 test_mm_mask3_fnmsub_ss(__m128 __W, __m128 __X, __m128 __Y, __mmask8 __U){
   // CHECK-LABEL: @test_mm_mask3_fnmsub_ss
-  // CHECK: @llvm.x86.avx512.mask3.vfmadd.ss
+  // CHECK: @llvm.x86.avx512.mask3.vfnmsub.ss
   return _mm_mask3_fnmsub_ss(__W, __X, __Y, __U);
 }
 
 __m128 test_mm_mask3_fnmsub_round_ss(__m128 __W, __m128 __X, __m128 __Y, __mmask8 __U){
   // CHECK-LABEL: @test_mm_mask3_fnmsub_round_ss
-  // CHECK: @llvm.x86.avx512.mask3.vfmadd.ss
+  // CHECK: @llvm.x86.avx512.mask3.vfnmsub.ss
   return _mm_mask3_fnmsub_round_ss(__W, __X, __Y, __U, _MM_FROUND_CUR_DIRECTION);
 }
 
@@ -5957,13 +5957,13 @@
 
 __m128d test_mm_mask3_fmsub_sd(__m128d __W, __m128d __X, __m128d __Y, __mmask8 __U){
   // CHECK-LABEL: @test_mm_mask3_fmsub_sd
-  // CHECK: @llvm.x86.avx512.mask3.vfmadd.sd
+  // CHECK: @llvm.x86.avx512.mask3.vfmsub.sd
   return _mm_mask3_fmsub_sd(__W, __X, __Y, __U);
 }
 
 __m128d test_mm_mask3_fmsub_round_sd(__m128d __W, __m128d __X, __m128d __Y, __mmask8 __U){
   // CHECK-LABEL: @test_mm_mask3_fmsub_round_sd
-  // CHECK: @llvm.x86.avx512.mask3.vfmadd.sd
+  // CHECK: @llvm.x86.avx512.mask3.vfmsub.sd
   return _mm_mask3_fmsub_round_sd(__W, __X, __Y, __U, _MM_FROUND_CUR_DIRECTION);
 }
 
@@ -6029,13 +6029,13 @@
 
 __m128d test_mm_mask3_fnmsub_sd(__m128d __W, __m128d __X, __m128d __Y, __mmask8 __U){
   // CHECK-LABEL: @test_mm_mask3_fnmsub_sd
-  // CHECK: @llvm.x86.avx512.mask3.vfmadd.sd
+  // CHECK: @llvm.x86.avx512.mask3.vfnmsub.sd
   return _mm_mask3_fnmsub_sd(__W, __X, __Y, __U);
 }
 
 __m128d test_mm_mask3_fnmsub_round_sd(__m128d __W, __m128d __X, __m128d __Y, __mmask8 __U){
   // CHECK-LABEL: @test_mm_mask3_fnmsub_round_sd
-  // CHECK: @llvm.x86.avx512.mask3.vfmadd.sd
+  // CHECK: @llvm.x86.avx512.mask3.vfnmsub.sd
   return _mm_mask3_fnmsub_round_sd(__W, __X, __Y, __U, _MM_FROUND_CUR_DIRECTION);
 }
 
Index: cfe/trunk/lib/Headers/avx512fintrin.h
===
--- cfe/trunk/lib/Headers/avx512fintrin.h
+++ cfe/trunk/lib/Headers/avx512fintrin.h
@@ -8470,17 +8470,17 @@
 static __inline__ __m128 __DEFAULT_FN_ATTRS
 _mm_mask3_fmsub_ss (__m128 __W, __m128 __X, __m128 __Y, __mmask8 __U)
 {
- return (__m128) __builtin_ia32_vfmaddss3_mask3 ((__v4sf) __W,
+ return (__m128) __builtin_ia32_vfmsubss3_mask3 ((__v4sf) __W,
   (__v4sf) __X,
-  -(__v4sf) __Y,
+  (__v4sf) __Y,
   (__mmask8) __U,
   _MM_FROUND_CUR_DIRECTION);
 }
 
 #define _mm_mask3_fmsub_round_ss(W, X, Y, U, R) __extension__ ({\
-  

[PATCH] D25727: [analyzer] Handle case of undefined values in performTrivialCopy

2016-10-31 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285640: [analyzer] Allow undefined values in 
performTrivialCopy. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D25727?vs=74994=76482#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25727

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  cfe/trunk/test/Analysis/uninit-vals.cpp


Index: cfe/trunk/test/Analysis/uninit-vals.cpp
===
--- cfe/trunk/test/Analysis/uninit-vals.cpp
+++ cfe/trunk/test/Analysis/uninit-vals.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core.builtin -verify 
-DCHECK_FOR_CRASH %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
+
+#ifdef CHECK_FOR_CRASH
+// expected-no-diagnostics
+#endif
+
+namespace PerformTrivialCopyForUndefs {
+struct A {
+  int x;
+};
+
+struct B {
+  A a;
+};
+
+struct C {
+  B b;
+};
+
+void foo() {
+  C c1;
+  C *c2;
+#ifdef CHECK_FOR_CRASH
+  // If the value of variable is not defined and checkers that check undefined
+  // values are not enabled, performTrivialCopy should be able to handle the
+  // case with undefined values, too.
+  c1.b.a = c2->b.a;
+#else
+  c1.b.a = c2->b.a; // expected-warning{{Function call argument is an 
uninitialized value}}
+#endif
+}
+}
+
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -65,7 +65,7 @@
   if (Optional L = V.getAs())
 V = Pred->getState()->getSVal(*L);
   else
-assert(V.isUnknown());
+assert(V.isUnknownOrUndef());
 
   const Expr *CallExpr = Call.getOriginExpr();
   evalBind(Dst, CallExpr, Pred, ThisVal, V, true);


Index: cfe/trunk/test/Analysis/uninit-vals.cpp
===
--- cfe/trunk/test/Analysis/uninit-vals.cpp
+++ cfe/trunk/test/Analysis/uninit-vals.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core.builtin -verify -DCHECK_FOR_CRASH %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
+
+#ifdef CHECK_FOR_CRASH
+// expected-no-diagnostics
+#endif
+
+namespace PerformTrivialCopyForUndefs {
+struct A {
+  int x;
+};
+
+struct B {
+  A a;
+};
+
+struct C {
+  B b;
+};
+
+void foo() {
+  C c1;
+  C *c2;
+#ifdef CHECK_FOR_CRASH
+  // If the value of variable is not defined and checkers that check undefined
+  // values are not enabled, performTrivialCopy should be able to handle the
+  // case with undefined values, too.
+  c1.b.a = c2->b.a;
+#else
+  c1.b.a = c2->b.a; // expected-warning{{Function call argument is an uninitialized value}}
+#endif
+}
+}
+
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -65,7 +65,7 @@
   if (Optional L = V.getAs())
 V = Pred->getState()->getSVal(*L);
   else
-assert(V.isUnknown());
+assert(V.isUnknownOrUndef());
 
   const Expr *CallExpr = Call.getOriginExpr();
   evalBind(Dst, CallExpr, Pred, ThisVal, V, true);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26159: [analyzer] MacOSXAPIChecker: Improve warning messages for __block vars in dispatch_once().

2016-10-31 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285637: [analyzer] MacOSXAPIChecker: Improve warnings for 
__block vars in dispatch_once. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D26159?vs=76453=76478#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26159

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
  cfe/trunk/test/Analysis/dispatch-once.m


Index: cfe/trunk/test/Analysis/dispatch-once.m
===
--- cfe/trunk/test/Analysis/dispatch-once.m
+++ cfe/trunk/test/Analysis/dispatch-once.m
@@ -90,3 +90,20 @@
 void test_ivar_array_from_external_obj(Object *o) {
   dispatch_once(>once_array[1], ^{}); // expected-warning{{Call to 
'dispatch_once' uses memory within the instance variable 'once_array' for the 
predicate value.}}
 }
+
+void test_block_var_from_block() {
+  __block dispatch_once_t once;
+  ^{
+dispatch_once(, ^{}); // expected-warning{{Call to 'dispatch_once' 
uses the block variable 'once' for the predicate value.}}
+  };
+}
+
+void use_block_var(dispatch_once_t *once);
+
+void test_block_var_from_outside_block() {
+  __block dispatch_once_t once;
+  ^{
+use_block_var();
+  };
+  dispatch_once(, ^{}); // expected-warning{{Call to 'dispatch_once' uses 
the block variable 'once' for the predicate value.}}
+}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
@@ -94,10 +94,15 @@
   bool SuggestStatic = false;
   os << "Call to '" << FName << "' uses";
   if (const VarRegion *VR = dyn_cast(RB)) {
-// We filtered out globals earlier, so it must be a local variable.
+// We filtered out globals earlier, so it must be a local variable
+// or a block variable which is under UnknownSpaceRegion.
 if (VR != R)
   os << " memory within";
-os << " the local variable '" << VR->getDecl()->getName() << '\'';
+if (VR->getDecl()->hasAttr())
+  os << " the block variable '";
+else
+  os << " the local variable '";
+os << VR->getDecl()->getName() << '\'';
 SuggestStatic = true;
   } else if (const ObjCIvarRegion *IVR = getParentIvarRegion(R)) {
 if (IVR != R)
@@ -108,6 +113,9 @@
   } else if (isa(RS)) {
 // Presence of an IVar superregion has priority over this branch, because
 // ObjC objects are on the heap even if the core doesn't realize this.
+// Presence of a block variable base region has priority over this branch,
+// because block variables are known to be either on stack or on heap
+// (might actually move between the two, hence UnknownSpace).
 return;
   } else {
 os << " stack allocated memory";


Index: cfe/trunk/test/Analysis/dispatch-once.m
===
--- cfe/trunk/test/Analysis/dispatch-once.m
+++ cfe/trunk/test/Analysis/dispatch-once.m
@@ -90,3 +90,20 @@
 void test_ivar_array_from_external_obj(Object *o) {
   dispatch_once(>once_array[1], ^{}); // expected-warning{{Call to 'dispatch_once' uses memory within the instance variable 'once_array' for the predicate value.}}
 }
+
+void test_block_var_from_block() {
+  __block dispatch_once_t once;
+  ^{
+dispatch_once(, ^{}); // expected-warning{{Call to 'dispatch_once' uses the block variable 'once' for the predicate value.}}
+  };
+}
+
+void use_block_var(dispatch_once_t *once);
+
+void test_block_var_from_outside_block() {
+  __block dispatch_once_t once;
+  ^{
+use_block_var();
+  };
+  dispatch_once(, ^{}); // expected-warning{{Call to 'dispatch_once' uses the block variable 'once' for the predicate value.}}
+}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
@@ -94,10 +94,15 @@
   bool SuggestStatic = false;
   os << "Call to '" << FName << "' uses";
   if (const VarRegion *VR = dyn_cast(RB)) {
-// We filtered out globals earlier, so it must be a local variable.
+// We filtered out globals earlier, so it must be a local variable
+// or a block variable which is under UnknownSpaceRegion.
 if (VR != R)
   os << " memory within";
-os << " the local variable '" << VR->getDecl()->getName() << '\'';
+if (VR->getDecl()->hasAttr())
+  os << " the block variable '";
+else
+  os << " the local variable '";
+os << VR->getDecl()->getName() << '\'';
 SuggestStatic = true;
   } else if (const ObjCIvarRegion *IVR = getParentIvarRegion(R)) {
 if (IVR != R)
@@ -108,6 +113,9 @@
   } else if (isa(RS)) {
 // Presence of an IVar superregion has priority over this branch, because
 // ObjC 

[PATCH] D25940: [analyzer] LibraryFunctions: Fix errors due to different integral types and typedefs on different architectures.

2016-11-02 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285852: [analyzer] StdLibraryFunctions: provide 
platform-specific function summaries. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D25940?vs=76731=76771#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25940

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  cfe/trunk/test/Analysis/std-c-library-functions.c

Index: cfe/trunk/test/Analysis/std-c-library-functions.c
===
--- cfe/trunk/test/Analysis/std-c-library-functions.c
+++ cfe/trunk/test/Analysis/std-c-library-functions.c
@@ -1,4 +1,8 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
+// RUN: %clang_cc1 -triple i686-unknown-linux -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
+// RUN: %clang_cc1 -triple armv7-a15-linux -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
+// RUN: %clang_cc1 -triple thumbv7-a15-linux -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
 
 void clang_analyzer_eval(int);
 
@@ -23,7 +27,7 @@
 }
 
 
-typedef unsigned long size_t;
+typedef typeof(sizeof(int)) size_t;
 typedef signed long ssize_t;
 ssize_t read(int, void *, size_t);
 ssize_t write(int, const void *, size_t);
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -79,11 +79,15 @@
   /// impose a constraint that involves other argument or return value symbols.
   enum ValueRangeKindTy { OutOfRange, WithinRange, ComparesToArgument };
 
+  // The universal integral type to use in value range descriptions.
+  // Unsigned to make sure overflows are well-defined.
+  typedef uint64_t RangeIntTy;
+
   /// Normally, describes a single range constraint, eg. {{0, 1}, {3, 4}} is
   /// a non-negative integer, which less than 5 and not equal to 2. For
   /// `ComparesToArgument', holds information about how exactly to compare to
   /// the argument.
-  typedef std::vector> IntRangeVectorTy;
+  typedef std::vector> IntRangeVectorTy;
 
   /// A reference to an argument or return value by its number.
   /// ArgNo in CallExpr and CallEvent is defined as Unsigned, but
@@ -190,9 +194,16 @@
 bool matchesCall(const CallExpr *CE) const;
   };
 
+  // The same function (as in, function identifier) may have different
+  // summaries assigned to it, with different argument and return value types.
+  // We call these "variants" of the function. This can be useful for handling
+  // C++ function overloads, and also it can be used when the same function
+  // may have different definitions on different platforms.
+  typedef std::vector FunctionVariantsTy;
+
   // The map of all functions supported by the checker. It is initialized
   // lazily, and it doesn't change after initialization.
-  typedef llvm::StringMap FunctionSummaryMapTy;
+  typedef llvm::StringMap FunctionSummaryMapTy;
   mutable FunctionSummaryMapTy FunctionSummaryMap;
 
   // Auxiliary functions to support ArgNoTy within all structures
@@ -442,11 +453,12 @@
   // Strict checking is important because we will be conducting
   // very integral-type-sensitive operations on arguments and
   // return values.
-  const FunctionSummaryTy  = FSMI->second;
-  if (!Spec.matchesCall(CE))
-return None;
+  const FunctionVariantsTy  = FSMI->second;
+  for (const FunctionSummaryTy  : SpecVariants)
+if (Spec.matchesCall(CE))
+  return Spec;
 
-  return Spec;
+  return None;
 }
 
 void StdLibraryFunctionsChecker::initFunctionSummaries(
@@ -458,17 +470,20 @@
 
   // These types are useful for writing specifications quickly,
   // New specifications should probably introduce more types.
+  // Some types are hard to obtain from the AST, eg. "ssize_t".
+  // In such cases it should be possible to provide multiple variants
+  // of function summary for common cases (eg. ssize_t could be int or long
+  // or long long, so three summary variants would be enough).
+  // Of course, function variants are also useful for C++ overloads.
   QualType Irrelevant; // A placeholder, whenever we do not care about the type.
   QualType IntTy = ACtx.IntTy;
+  QualType LongTy = ACtx.LongTy;
+  QualType LongLongTy = ACtx.LongLongTy;
   QualType SizeTy = ACtx.getSizeType();
-  QualType SSizeTy = ACtx.getIntTypeForBitwidth(ACtx.getTypeSize(SizeTy), true);
 
-  // Don't worry about truncation here, it'd be cast back to SIZE_MAX when used.
-  

[PATCH] D26176: [Clang-tidy] Fix copy-paste error in misc-redundant-expression detected by PVS-Studio

2016-11-01 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285721: [Clang-tidy] Fix copy-paste error in 
misc-redundant-expression detected by PVS… (authored by eugenezelenko).

Changed prior to commit:
  https://reviews.llvm.org/D26176?vs=76510=76611#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26176

Files:
  clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp


Index: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -12,7 +12,20 @@
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 using namespace clang::tidy::matchers;
@@ -171,7 +184,7 @@
   }
 
   // Handle cases where the constants are different.
-  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LE || OpcodeLHS == BO_LE) &&
+  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LT || OpcodeLHS == BO_LE) &&
   (OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE))
 return true;
 
@@ -401,7 +414,7 @@
 // Operand received with implicit comparator (cast).
 Opcode = BO_NE;
 OperandExpr = Cast;
-Value = APSInt(32, 0);
+Value = APSInt(32, false);
   } else {
 return false;
   }


Index: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -12,7 +12,20 @@
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 using namespace clang::tidy::matchers;
@@ -171,7 +184,7 @@
   }
 
   // Handle cases where the constants are different.
-  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LE || OpcodeLHS == BO_LE) &&
+  if ((OpcodeLHS == BO_EQ || OpcodeLHS == BO_LT || OpcodeLHS == BO_LE) &&
   (OpcodeRHS == BO_EQ || OpcodeRHS == BO_GT || OpcodeRHS == BO_GE))
 return true;
 
@@ -401,7 +414,7 @@
 // Operand received with implicit comparator (cast).
 Opcode = BO_NE;
 OperandExpr = Cast;
-Value = APSInt(32, 0);
+Value = APSInt(32, false);
   } else {
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26067: [openmp] Remove test assumption that canonical binary name contains "clang"

2016-10-28 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285388: [openmp] Remove test assumption that canonical 
binary name contains "clang" (authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D26067?vs=76172=76174#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26067

Files:
  cfe/trunk/test/Driver/openmp-offload.c


Index: cfe/trunk/test/Driver/openmp-offload.c
===
--- cfe/trunk/test/Driver/openmp-offload.c
+++ cfe/trunk/test/Driver/openmp-offload.c
@@ -184,15 +184,15 @@
 /// We use -fopenmp-dump-offload-linker-script to dump the linker script and
 /// check its contents.
 ///
-// RUN:   %clang -### -fopenmp=libomp -o %t.out -target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s 
-fopenmp-dump-offload-linker-script 2>&1 \
+// RUN:   %clang -### -fopenmp=libomp -o %t.out -target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s 
-fopenmp-dump-offload-linker-script -no-canonical-prefixes 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-COMMANDS -check-prefix=CHK-LKS 
-check-prefix=CHK-LKS-REG %s
-// RUN:   %clang -### -fopenmp=libomp -o %t.out -target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s -save-temps 
-fopenmp-dump-offload-linker-script 2>&1 \
+// RUN:   %clang -### -fopenmp=libomp -o %t.out -target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s -save-temps 
-fopenmp-dump-offload-linker-script -no-canonical-prefixes 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-COMMANDS-ST -check-prefix=CHK-LKS 
-check-prefix=CHK-LKS-ST %s
 
 // Make sure we are not dumping the script unless the user requested it.
-// RUN:   %clang -### -fopenmp=libomp -o %t.out -target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s 2>&1 \
+// RUN:   %clang -### -fopenmp=libomp -o %t.out -target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s 
-no-canonical-prefixes 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-LKS-NODUMP %s
-// RUN:   %clang -### -fopenmp=libomp -o %t.out -target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s -save-temps 
2>&1 \
+// RUN:   %clang -### -fopenmp=libomp -o %t.out -target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s -save-temps 
-no-canonical-prefixes 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-LKS-NODUMP %s
 
 //
@@ -275,7 +275,7 @@
 /// ###
 
 /// Check separate compilation with offloading - bundling actions
-// RUN:   %clang -### -ccc-print-phases -fopenmp=libomp -c -o %t.o -lsomelib 
-target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s 2>&1 \
+// RUN:   %clang -### -ccc-print-phases -fopenmp=libomp -c -o %t.o -lsomelib 
-target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s 
-no-canonical-prefixes 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BUACTIONS %s
 
 // CHK-BUACTIONS: 0: input, "[[INPUT:.+\.c]]", c, (host-openmp)
@@ -303,7 +303,7 @@
 
 /// Check separate compilation with offloading - unbundling actions
 // RUN:   touch %t.i
-// RUN:   %clang -### -ccc-print-phases -fopenmp=libomp -o %t.out -lsomelib 
-target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %t.i 2>&1 \
+// RUN:   %clang -### -ccc-print-phases -fopenmp=libomp -o %t.out -lsomelib 
-target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %t.i 
-no-canonical-prefixes 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-UBACTIONS %s
 
 // CHK-UBACTIONS: 0: input, "somelib", object, (host-openmp)
@@ -331,7 +331,7 @@
 
 /// Check separate compilation with offloading - unbundling/bundling actions
 // RUN:   touch %t.i
-// RUN:   %clang -### -ccc-print-phases -fopenmp=libomp -c -o %t.o -lsomelib 
-target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %t.i 2>&1 \
+// RUN:   %clang -### -ccc-print-phases -fopenmp=libomp -c -o %t.o -lsomelib 
-target powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %t.i 
-no-canonical-prefixes 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-UBUACTIONS %s
 
 // CHK-UBUACTIONS: 0: input, "[[INPUT:.+\.i]]", cpp-output, (host-openmp)
@@ -354,9 +354,9 @@
 /// ###
 
 /// Check separate compilation with offloading - bundling jobs construct
-// RUN:   %clang -### -fopenmp=libomp -c -o %t.o -lsomelib -target 
powerpc64le-linux 
-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu %s 2>&1 \
+// RUN:   %clang -### -fopenmp=libomp -c -o %t.o -lsomelib -target 
powerpc64le-linux 

[PATCH] D25731: [analyzer] NumberObjectConversion: Support OSNumber and CFNumberRef.

2016-10-30 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285533: [analyzer] NumberObjectConversion: support more 
types, misc updates. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D25731?vs=76043=76349#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25731

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  cfe/trunk/test/Analysis/number-object-conversion.c
  cfe/trunk/test/Analysis/number-object-conversion.cpp
  cfe/trunk/test/Analysis/number-object-conversion.m

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
@@ -63,33 +63,30 @@
 } // end of anonymous namespace
 
 void Callback::run(const MatchFinder::MatchResult ) {
-  bool IsPedanticMatch = (Result.Nodes.getNodeAs("pedantic") != nullptr);
+  bool IsPedanticMatch =
+  (Result.Nodes.getNodeAs("pedantic") != nullptr);
   if (IsPedanticMatch && !C->Pedantic)
 return;
 
-  const Stmt *Conv = Result.Nodes.getNodeAs("conv");
-  assert(Conv);
-  const Expr *Osboolean = Result.Nodes.getNodeAs("osboolean");
-  const Expr *Nsnumber = Result.Nodes.getNodeAs("nsnumber");
-  bool IsObjC = (bool)Nsnumber;
-  const Expr *Obj = IsObjC ? Nsnumber : Osboolean;
-  assert(Obj);
-
   ASTContext  = ADC->getASTContext();
 
   if (const Expr *CheckIfNull =
   Result.Nodes.getNodeAs("check_if_null")) {
-// We consider NULL to be a pointer, even if it is defined as a plain 0.
-// FIXME: Introduce a matcher to implement this logic?
+// Unless the macro indicates that the intended type is clearly not
+// a pointer type, we should avoid warning on comparing pointers
+// to zero literals in non-pedantic mode.
+// FIXME: Introduce an AST matcher to implement the macro-related logic?
+bool MacroIndicatesWeShouldSkipTheCheck = false;
 SourceLocation Loc = CheckIfNull->getLocStart();
 if (Loc.isMacroID()) {
   StringRef MacroName = Lexer::getImmediateMacroName(
   Loc, ACtx.getSourceManager(), ACtx.getLangOpts());
-  if (MacroName != "YES" && MacroName != "NO")
+  if (MacroName == "NULL" || MacroName == "nil")
 return;
-} else {
-  // Otherwise, comparison of pointers to 0 might still be intentional.
-  // See if this is the case.
+  if (MacroName == "YES" || MacroName == "NO")
+MacroIndicatesWeShouldSkipTheCheck = true;
+}
+if (!MacroIndicatesWeShouldSkipTheCheck) {
   llvm::APSInt Result;
   if (CheckIfNull->IgnoreParenCasts()->EvaluateAsInt(
   Result, ACtx, Expr::SE_AllowSideEffects)) {
@@ -102,33 +99,92 @@
 }
   }
 
+  const Stmt *Conv = Result.Nodes.getNodeAs("conv");
+  assert(Conv);
+
+  const Expr *ConvertedCObject = Result.Nodes.getNodeAs("c_object");
+  const Expr *ConvertedCppObject = Result.Nodes.getNodeAs("cpp_object");
+  const Expr *ConvertedObjCObject = Result.Nodes.getNodeAs("objc_object");
+  bool IsCpp = (ConvertedCppObject != nullptr);
+  bool IsObjC = (ConvertedObjCObject != nullptr);
+  const Expr *Obj = IsObjC ? ConvertedObjCObject
+  : IsCpp ? ConvertedCppObject
+  : ConvertedCObject;
+  assert(Obj);
+
+  bool IsComparison =
+  (Result.Nodes.getNodeAs("comparison") != nullptr);
+
+  bool IsOSNumber =
+  (Result.Nodes.getNodeAs("osnumber") != nullptr);
+
+  bool IsInteger =
+  (Result.Nodes.getNodeAs("int_type") != nullptr);
+  bool IsObjCBool =
+  (Result.Nodes.getNodeAs("objc_bool_type") != nullptr);
+  bool IsCppBool =
+  (Result.Nodes.getNodeAs("cpp_bool_type") != nullptr);
+
   llvm::SmallString<64> Msg;
   llvm::raw_svector_ostream OS(Msg);
-  OS << "Converting '"
- << Obj->getType().getCanonicalType().getUnqualifiedType().getAsString()
- << "' to a plain ";
-
-  if (Result.Nodes.getNodeAs("int_type") != nullptr)
-OS << "integer value";
-  else if (Result.Nodes.getNodeAs("objc_bool_type") != nullptr)
-OS << "BOOL value";
-  else if (Result.Nodes.getNodeAs("cpp_bool_type") != nullptr)
-OS << "bool value";
+
+  // Remove ObjC ARC qualifiers.
+  QualType ObjT = Obj->getType().getUnqualifiedType();
+
+  // Remove consts from pointers.
+  if (IsCpp) {
+assert(ObjT.getCanonicalType()->isPointerType());
+ObjT = ACtx.getPointerType(
+ObjT->getPointeeType().getCanonicalType().getUnqualifiedType());
+  }
+
+  if (IsComparison)
+OS << "Comparing ";
   else
-OS << "boolean value for branching";
+OS << "Converting ";
 
-  if (IsPedanticMatch) {
-if (IsObjC) {
-  OS << "; please compare the pointer to nil instead "
-"to suppress this warning";
-} else {
-  OS << "; please compare the pointer to NULL or nullptr instead "
-"to suppress this warning";

[PATCH] D25012: [x86][inline-asm] Add support for curly brackets escape using "%" in extended inline asm.

2016-10-31 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285585: [x86][inline-asm] Add support for curly brackets 
escape using "%" in extended… (authored by mzuckerm).

Changed prior to commit:
  https://reviews.llvm.org/D25012?vs=73602=76415#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25012

Files:
  cfe/trunk/lib/AST/Stmt.cpp
  cfe/trunk/test/CodeGen/x86_inlineasm_curly_bracket_escape.c


Index: cfe/trunk/test/CodeGen/x86_inlineasm_curly_bracket_escape.c
===
--- cfe/trunk/test/CodeGen/x86_inlineasm_curly_bracket_escape.c
+++ cfe/trunk/test/CodeGen/x86_inlineasm_curly_bracket_escape.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-cpu skylake-avx512 
-O0  -S -emit-llvm -o - -Wall -Werror | FileCheck %s
+// This test checks validity of inline assembly using curly brackets syntax
+// for extended inline asm.
+
+void test_curly_brackets() {
+//CHECK:  %xmm1,%xmm0,%xmm1 {%k1}{z}
+asm("vpaddb\t %%xmm1,%%xmm0,%%xmm1 %{%%k1%}%{z%}\t":::);
+}
\ No newline at end of file
Index: cfe/trunk/lib/AST/Stmt.cpp
===
--- cfe/trunk/lib/AST/Stmt.cpp
+++ cfe/trunk/lib/AST/Stmt.cpp
@@ -533,15 +533,17 @@
   DiagOffs = CurPtr-StrStart-1;
   return diag::err_asm_invalid_escape;
 }
-
+// Handle escaped char and continue looping over the asm string.
 char EscapedChar = *CurPtr++;
-if (EscapedChar == '%') {  // %% -> %
-  // Escaped percentage sign.
-  CurStringPiece += '%';
+switch (EscapedChar) {
+default:
+  break;
+case '%': // %% -> %
+case '{': // %{ -> {
+case '}': // %} -> }
+  CurStringPiece += EscapedChar;
   continue;
-}
-
-if (EscapedChar == '=') {  // %= -> Generate an unique ID.
+case '=': // %= -> Generate a unique ID.
   CurStringPiece += "${:uid}";
   continue;
 }


Index: cfe/trunk/test/CodeGen/x86_inlineasm_curly_bracket_escape.c
===
--- cfe/trunk/test/CodeGen/x86_inlineasm_curly_bracket_escape.c
+++ cfe/trunk/test/CodeGen/x86_inlineasm_curly_bracket_escape.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-cpu skylake-avx512 -O0  -S -emit-llvm -o - -Wall -Werror | FileCheck %s
+// This test checks validity of inline assembly using curly brackets syntax
+// for extended inline asm.
+
+void test_curly_brackets() {
+//CHECK:  %xmm1,%xmm0,%xmm1 {%k1}{z}
+asm("vpaddb\t %%xmm1,%%xmm0,%%xmm1 %{%%k1%}%{z%}\t":::);
+}
\ No newline at end of file
Index: cfe/trunk/lib/AST/Stmt.cpp
===
--- cfe/trunk/lib/AST/Stmt.cpp
+++ cfe/trunk/lib/AST/Stmt.cpp
@@ -533,15 +533,17 @@
   DiagOffs = CurPtr-StrStart-1;
   return diag::err_asm_invalid_escape;
 }
-
+// Handle escaped char and continue looping over the asm string.
 char EscapedChar = *CurPtr++;
-if (EscapedChar == '%') {  // %% -> %
-  // Escaped percentage sign.
-  CurStringPiece += '%';
+switch (EscapedChar) {
+default:
+  break;
+case '%': // %% -> %
+case '{': // %{ -> {
+case '}': // %} -> }
+  CurStringPiece += EscapedChar;
   continue;
-}
-
-if (EscapedChar == '=') {  // %= -> Generate an unique ID.
+case '=': // %= -> Generate a unique ID.
   CurStringPiece += "${:uid}";
   continue;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25062: [x86][inline-asm][AVX512][llvm][PART-2] Introducing "k" and "Yk" constraints for extended inline assembly, enabling use of AVX512 masked vectorized instructions.

2016-10-31 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285591: [x86][inline-asm][AVX512][llvm][PART-2] (authored by 
mzuckerm).

Changed prior to commit:
  https://reviews.llvm.org/D25062?vs=75278=76429#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25062

Files:
  llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Index: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
===
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
@@ -32319,6 +32319,7 @@
 case 'Y':
 case 'l':
   return C_RegisterClass;
+case 'k': // AVX512 masking registers.
 case 'a':
 case 'b':
 case 'c':
@@ -32342,6 +32343,19 @@
   break;
 }
   }
+  else if (Constraint.size() == 2) {
+switch (Constraint[0]) {
+default:
+  break;
+case 'Y':
+  switch (Constraint[1]) {
+  default:
+break;
+  case 'k':
+return C_Register;
+  }
+}
+  }
   return TargetLowering::getConstraintType(Constraint);
 }
 
@@ -32385,16 +32399,28 @@
 if (type->isX86_MMXTy() && Subtarget.hasMMX())
   weight = CW_SpecificReg;
 break;
+  case 'Y':
+// Other "Y" (e.g. "Yk") constraints should be implemented below.
+if (constraint[1] == 'k') {
+  // Support for 'Yk' (similarly to the 'k' variant below).
+  weight = CW_SpecificReg;
+  break;
+}
+  // Else fall through (handle "Y" constraint).
+LLVM_FALLTHROUGH;
   case 'v':
 if ((type->getPrimitiveSizeInBits() == 512) && Subtarget.hasAVX512())
   weight = CW_Register;
 LLVM_FALLTHROUGH;
   case 'x':
-  case 'Y':
 if (((type->getPrimitiveSizeInBits() == 128) && Subtarget.hasSSE1()) ||
 ((type->getPrimitiveSizeInBits() == 256) && Subtarget.hasFp256()))
   weight = CW_Register;
 break;
+  case 'k':
+// Enable conditional vector operations using %k<#> registers.
+weight = CW_SpecificReg;
+break;
   case 'I':
 if (ConstantInt *C = dyn_cast(info.CallOperandVal)) {
   if (C->getZExtValue() <= 31)
@@ -32671,6 +32697,24 @@
   // TODO: Slight differences here in allocation order and leaving
   // RIP in the class. Do they matter any more here than they do
   // in the normal allocation?
+case 'k':
+  if (Subtarget.hasAVX512()) {
+//  Only supported in AVX512 or later.
+switch (VT.SimpleTy) {
+default: break;
+case MVT::i32:
+  return std::make_pair(0U, ::VK32RegClass);
+case MVT::i16:
+  return std::make_pair(0U, ::VK16RegClass);
+case MVT::i8:
+  return std::make_pair(0U, ::VK8RegClass);
+case MVT::i1:
+  return std::make_pair(0U, ::VK1RegClass);
+case MVT::i64:
+  return std::make_pair(0U, ::VK64RegClass);
+}
+  }
+  break;
 case 'q':   // GENERAL_REGS in 64-bit mode, Q_REGS in 32-bit mode.
   if (Subtarget.is64Bit()) {
 if (VT == MVT::i32 || VT == MVT::f32)
@@ -32772,6 +32816,29 @@
   }
   break;
 }
+  } else if (Constraint.size() == 2 && Constraint[0] == 'Y') {
+switch (Constraint[1]) {
+default:
+  break;
+case 'k':
+  // This register class doesn't allocate k0 for masked vector operation.
+  if (Subtarget.hasAVX512()) { // Only supported in AVX512.
+switch (VT.SimpleTy) {
+default: break;
+case MVT::i32:
+  return std::make_pair(0U, ::VK32WMRegClass);
+case MVT::i16:
+  return std::make_pair(0U, ::VK16WMRegClass);
+case MVT::i8:
+  return std::make_pair(0U, ::VK8WMRegClass);
+case MVT::i1:
+  return std::make_pair(0U, ::VK1WMRegClass);
+case MVT::i64:
+  return std::make_pair(0U, ::VK64WMRegClass);
+} 
+  }
+  break;
+}
   }
 
   // Use the default implementation in TargetLowering to convert the register
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25909: [analyzer] MacOSXApiChecker: Disallow dispatch_once predicates on heap and in ivars.

2016-10-31 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285605: [analyzer] MacOSXAPIChecker: Disallow 
dispatch_once_t in ivars and heap. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D25909?vs=75998=76446#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25909

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  cfe/trunk/test/Analysis/dispatch-once.m

Index: cfe/trunk/test/Analysis/dispatch-once.m
===
--- cfe/trunk/test/Analysis/dispatch-once.m
+++ cfe/trunk/test/Analysis/dispatch-once.m
@@ -0,0 +1,92 @@
+// RUN: %clang_cc1 -w -fblocks -analyze -analyzer-checker=core,osx.API,unix.Malloc -verify %s
+// RUN: %clang_cc1 -w -fblocks -fobjc-arc -analyze -analyzer-checker=core,osx.API,unix.Malloc -verify %s
+
+#include "Inputs/system-header-simulator-objc.h"
+
+typedef unsigned long size_t;
+void *calloc(size_t nmemb, size_t size);
+
+typedef void (^dispatch_block_t)(void);
+typedef long dispatch_once_t;
+void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);
+
+void test_stack() {
+  dispatch_once_t once;
+  dispatch_once(, ^{}); // expected-warning{{Call to 'dispatch_once' uses the local variable 'once' for the predicate value.  Using such transient memory for the predicate is potentially dangerous.  Perhaps you intended to declare the variable as 'static'?}}
+}
+
+void test_static_local() {
+  static dispatch_once_t once;
+  dispatch_once(, ^{}); // no-warning
+}
+
+void test_heap_var() {
+  dispatch_once_t *once = calloc(1, sizeof(dispatch_once_t));
+  // Use regexps to check that we're NOT suggesting to make this static.
+  dispatch_once(once, ^{}); // expected-warning-re^Call to 'dispatch_once' uses heap-allocated memory for the predicate value.  Using such transient memory for the predicate is potentially dangerous$
+}
+
+void test_external_pointer(dispatch_once_t *once) {
+  // External pointer does not necessarily point to the heap.
+  dispatch_once(once, ^{}); // no-warning
+}
+
+typedef struct {
+  dispatch_once_t once;
+} Struct;
+
+void test_local_struct() {
+  Struct s;
+  dispatch_once(, ^{}); // expected-warning{{Call to 'dispatch_once' uses memory within the local variable 's' for the predicate value.}}
+}
+
+void test_heap_struct() {
+  Struct *s = calloc(1, sizeof(Struct));
+  dispatch_once(>once, ^{}); // expected-warning{{Call to 'dispatch_once' uses heap-allocated memory for the predicate value.}}
+}
+
+@interface Object : NSObject {
+@public
+  dispatch_once_t once;
+  Struct s;
+  dispatch_once_t once_array[2];
+}
+- (void)test_ivar_from_inside;
+- (void)test_ivar_struct_from_inside;
+@end
+
+@implementation Object
+- (void)test_ivar_from_inside {
+  dispatch_once(, ^{}); // expected-warning{{Call to 'dispatch_once' uses the instance variable 'once' for the predicate value.}}
+}
+- (void)test_ivar_struct_from_inside {
+  dispatch_once(, ^{}); // expected-warning{{Call to 'dispatch_once' uses memory within the instance variable 's' for the predicate value.}}
+}
+- (void)test_ivar_array_from_inside {
+  dispatch_once(_array[1], ^{}); // expected-warning{{Call to 'dispatch_once' uses memory within the instance variable 'once_array' for the predicate value.}}
+}
+@end
+
+void test_ivar_from_alloc_init() {
+  Object *o = [[Object alloc] init];
+  dispatch_once(>once, ^{}); // expected-warning{{Call to 'dispatch_once' uses the instance variable 'once' for the predicate value.}}
+}
+void test_ivar_struct_from_alloc_init() {
+  Object *o = [[Object alloc] init];
+  dispatch_once(>s.once, ^{}); // expected-warning{{Call to 'dispatch_once' uses memory within the instance variable 's' for the predicate value.}}
+}
+void test_ivar_array_from_alloc_init() {
+  Object *o = [[Object alloc] init];
+  dispatch_once(>once_array[1], ^{}); // expected-warning{{Call to 'dispatch_once' uses memory within the instance variable 'once_array' for the predicate value.}}
+}
+
+void test_ivar_from_external_obj(Object *o) {
+  // ObjC object pointer always points to the heap.
+  dispatch_once(>once, ^{}); // expected-warning{{Call to 'dispatch_once' uses the instance variable 'once' for the predicate value.}}
+}
+void test_ivar_struct_from_external_obj(Object *o) {
+  dispatch_once(>s.once, ^{}); // expected-warning{{Call to 'dispatch_once' uses memory within the instance variable 's' for the predicate value.}}
+}
+void test_ivar_array_from_external_obj(Object *o) {
+  dispatch_once(>once_array[1], ^{}); // expected-warning{{Call to 'dispatch_once' uses memory within the instance variable 'once_array' for the predicate value.}}
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ 

[PATCH] D25063: [x86][inline-asm][AVX512][clang][PART-1] Introducing "k" and "Yk" constraints for extended inline assembly, enabling use of AVX512 masked vectorized instructions.

2016-10-31 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285604: [x86][inline-asm][AVX512][clang][PART-1] Introducing 
"k" and "Yk" constraints… (authored by mzuckerm).

Changed prior to commit:
  https://reviews.llvm.org/D25063?vs=75542=76445#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25063

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/CodeGen/avx512-kconstraints-att_inline_asm.c

Index: cfe/trunk/test/CodeGen/avx512-kconstraints-att_inline_asm.c
===
--- cfe/trunk/test/CodeGen/avx512-kconstraints-att_inline_asm.c
+++ cfe/trunk/test/CodeGen/avx512-kconstraints-att_inline_asm.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-cpu skylake-avx512 -O0  -emit-llvm -S -o - -Wall -Werror | FileCheck %s
+// This test checks validity of att\gcc style inline assmebly for avx512 k and Yk constraints.
+// Also checks mask register allows flexible type (size <= 64 bit)
+
+void mask_Yk_i8(char msk){ 
+//CHECK: vpaddb %xmm1, %xmm0, %xmm1 {%k1}
+ asm ("vpaddb\t %%xmm1, %%xmm0, %%xmm1 %{%0%}\t"
+   ://output
+   : "Yk" (msk));   //inputs
+}
+
+void mask_Yk_i16(short msk){
+//CHECK: vpaddb %xmm1, %xmm0, %xmm1 {%k1}
+ asm ("vpaddb\t %%xmm1, %%xmm0, %%xmm1 %{%0%}\t"
+   ://output
+   :  "Yk" (msk));  //inputs
+}
+
+void mask_Yk_i32(int msk){
+//CHECK: vpaddb %xmm1, %xmm0, %xmm1 {%k1}
+asm ("vpaddb\t %%xmm1, %%xmm0, %%xmm1 %{%0%}\t"
+   ://output
+   :  "Yk" (msk));   //inputs
+}
+
+void mask_Yk_i64(long long msk){
+//CHECK: vpaddb %xmm1, %xmm0, %xmm1 {%k1}
+ asm ("vpaddb\t %%xmm1, %%xmm0, %%xmm1 %{%0%}\t"
+   ://output
+   :  "Yk" (msk));   //inputs
+}
+
+void k_wise_op_i8(char msk_dst,char msk_src1,char msk_src2){
+//CHECK: kandw %k1, %k0, %k0
+ asm ("kandw\t%2, %1, %0"
+   : "=k" (msk_dst)
+   : "k" (msk_src1), "k" (msk_src2));
+}
+
+void k_wise_op_i16(short msk_dst, short msk_src1, short msk_src2){
+//CHECK: kandw %k1, %k0, %k0
+  asm ("kandw\t%2, %1, %0"
+   : "=k" (msk_dst)
+   : "k" (msk_src1), "k" (msk_src2));
+}
+
+void k_wise_op_i32(int msk_dst, int msk_src1, int msk_src2){
+//CHECK: kandw %k1, %k0, %k0
+  asm ("kandw\t%2, %1, %0"
+   : "=k" (msk_dst)
+   : "k" (msk_src1), "k" (msk_src2));
+}
+
+void k_wise_op_i64(long long msk_dst, long long msk_src1, long long msk_src2){
+//CHECK: kandw %k1, %k0, %k0
+  asm ("kandw\t%2, %1, %0"
+   : "=k" (msk_dst)
+   : "k" (msk_src1), "k" (msk_src2));
+}
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -3997,6 +3997,7 @@
 case 't': // Any SSE register, when SSE2 is enabled.
 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
 case 'm': // Any MMX register, when inter-unit moves enabled.
+case 'k': // AVX512 arch mask registers: k1-k7.
   Info.setAllowsRegister();
   return true;
 }
@@ -4018,6 +4019,8 @@
   case 'q': // Any register accessible as [r]l: a, b, c, and d.
   case 'y': // Any MMX register.
   case 'x': // Any SSE register.
+  case 'k': // Any AVX512 mask register (same as Yk, additionaly allows k0
+// for intermideate k reg operations).
   case 'Q': // Any register accessible as [r]h: a, b, c, and d.
   case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
   case 'l': // "Index" registers: any general register that can be used as an
@@ -4051,6 +4054,8 @@
 unsigned Size) const {
   switch (Constraint[0]) {
   default: break;
+  case 'k':
+  // Registers k0-k7 (AVX512) size limit is 64 bit.
   case 'y':
 return Size <= 64;
   case 'f':
@@ -4071,6 +4076,7 @@
 default: break;
 case 'm':
   // 'Ym' is synonymous with 'y'.
+case 'k':
   return Size <= 64;
 case 'i':
 case 't':
@@ -4102,6 +4108,20 @@
 return std::string("{st}");
   case 'u': // second from top of floating point stack.
 return std::string("{st(1)}"); // second from top of floating point stack.
+  case 'Y':
+switch (Constraint[1]) {
+default:
+  // Break from inner switch and fall through (copy single char),
+  // continue parsing after copying the current constraint into 
+  // the return string.
+  break;
+case 'k':
+  // "^" hints llvm that this is a 2 letter constraint.
+  // "Constraint++" is used to promote the string iterator 
+  // to the next constraint.
+  return std::string("^") + std::string(Constraint++, 2);
+} 
+LLVM_FALLTHROUGH;
   default:
 return std::string(1, *Constraint);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25983: Fix use-after-free in ASTContext.

2016-10-26 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285192: Fix use-after-scope in ASTContext. (authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D25983?vs=75860=75865#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25983

Files:
  cfe/trunk/lib/AST/ASTContext.cpp


Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -3230,13 +3230,13 @@
 for (unsigned i = 0; i != NumArgs; ++i)
   CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i]));
 
+llvm::SmallVector ExceptionTypeStorage;
 FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI;
 CanonicalEPI.HasTrailingReturn = false;
 
 if (IsCanonicalExceptionSpec) {
   // Exception spec is already OK.
 } else if (NoexceptInType) {
-  llvm::SmallVector ExceptionTypeStorage;
   switch (EPI.ExceptionSpec.Type) {
   case EST_Unparsed: case EST_Unevaluated: case EST_Uninstantiated:
 // We don't know yet. It shouldn't matter what we pick here; no-one


Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -3230,13 +3230,13 @@
 for (unsigned i = 0; i != NumArgs; ++i)
   CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i]));
 
+llvm::SmallVector ExceptionTypeStorage;
 FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI;
 CanonicalEPI.HasTrailingReturn = false;
 
 if (IsCanonicalExceptionSpec) {
   // Exception spec is already OK.
 } else if (NoexceptInType) {
-  llvm::SmallVector ExceptionTypeStorage;
   switch (EPI.ExceptionSpec.Type) {
   case EST_Unparsed: case EST_Unevaluated: case EST_Uninstantiated:
 // We don't know yet. It shouldn't matter what we pick here; no-one
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25429: [analyzer] Link libStaticAnalyzerCheckers to libASTMatchers.

2016-10-13 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284112: [analyzer] Link libStaticAnalyzerCheckers to 
libASTMatchers. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D25429?vs=74109=74497#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25429

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -91,6 +91,7 @@
 
   LINK_LIBS
   clangAST
+  clangASTMatchers
   clangAnalysis
   clangBasic
   clangLex


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -91,6 +91,7 @@
 
   LINK_LIBS
   clangAST
+  clangASTMatchers
   clangAnalysis
   clangBasic
   clangLex
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25283: AvailabilityAttrs: Refactor context checking when diagnosing an availability violation

2016-10-14 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284265: [Sema] Refactor context checking for availability 
diagnostics (authored by epilk).

Changed prior to commit:
  https://reviews.llvm.org/D25283?vs=74547=74729#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25283

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/SemaObjC/class-unavail-warning.m

Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -9889,23 +9889,16 @@
 return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
   }
 
-  AvailabilityResult getCurContextAvailability() const;
-
-  /// \brief Get the verison that this context implies.
-  /// For instance, a method in an interface that is annotated with an
-  /// availability attribuite effectively has the availability of the interface.
-  VersionTuple getVersionForDecl(const Decl *Ctx) const;
-
   /// \brief The diagnostic we should emit for \c D, or \c AR_Available.
   ///
   /// \param D The declaration to check. Note that this may be altered to point
   /// to another declaration that \c D gets it's availability from. i.e., we
   /// walk the list of typedefs to find an availability attribute.
   ///
-  /// \param ContextVersion The version to compare availability against.
-  AvailabilityResult
-  ShouldDiagnoseAvailabilityOfDecl(NamedDecl *, VersionTuple ContextVersion,
-   std::string *Message);
+  /// \param Message If non-null, this will be populated with the message from
+  /// the availability attribute that is selected.
+  AvailabilityResult ShouldDiagnoseAvailabilityOfDecl(NamedDecl *,
+  std::string *Message);
 
   const DeclContext *getCurObjCLexicalContext() const {
 const DeclContext *DC = getCurLexicalContext();
Index: cfe/trunk/test/SemaObjC/class-unavail-warning.m
===
--- cfe/trunk/test/SemaObjC/class-unavail-warning.m
+++ cfe/trunk/test/SemaObjC/class-unavail-warning.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1  -fsyntax-only  -triple x86_64-apple-darwin10 -verify %s
+// RUN: %clang_cc1  -fsyntax-only -fblocks -triple x86_64-apple-darwin10 -verify %s
 // rdar://9092208
 
 __attribute__((unavailable("not available")))
@@ -98,3 +98,19 @@
 @end
 @interface UnavailSub(cat) // no error
 @end
+
+int unavail_global UNAVAILABLE;
+
+UNAVAILABLE __attribute__((objc_root_class))
+@interface TestAttrContext
+-meth;
+@end
+
+@implementation TestAttrContext
+-meth {
+  unavail_global = 2; // no warn
+  (void) ^{
+unavail_global = 4; // no warn
+  };
+}
+@end
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -15615,29 +15615,3 @@
 Decl *Sema::getObjCDeclContext() const {
   return (dyn_cast_or_null(CurContext));
 }
-
-AvailabilityResult Sema::getCurContextAvailability() const {
-  const Decl *D = cast_or_null(getCurObjCLexicalContext());
-  if (!D)
-return AR_Available;
-
-  // If we are within an Objective-C method, we should consult
-  // both the availability of the method as well as the
-  // enclosing class.  If the class is (say) deprecated,
-  // the entire method is considered deprecated from the
-  // purpose of checking if the current context is deprecated.
-  if (const ObjCMethodDecl *MD = dyn_cast(D)) {
-AvailabilityResult R = MD->getAvailability();
-if (R != AR_Available)
-  return R;
-D = MD->getClassInterface();
-  }
-  // If we are within an Objective-c @implementation, it
-  // gets the same availability context as the @interface.
-  else if (const ObjCImplementationDecl *ID =
-dyn_cast(D)) {
-D = ID->getClassInterface();
-  }
-  // Recover from user error.
-  return D ? D->getAvailability() : AR_Available;
-}
Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -6317,30 +6317,6 @@
   diag.Triggered = true;
 }
 
-static bool isDeclDeprecated(Decl *D) {
-  do {
-if (D->isDeprecated())
-  return true;
-// A category implicitly has the availability of the interface.
-if (const ObjCCategoryDecl *CatD = dyn_cast(D))
-  if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface())
-return Interface->isDeprecated();
-  } while ((D = cast_or_null(D->getDeclContext(;
-  return false;
-}
-
-static bool isDeclUnavailable(Decl *D) {
-  do {
-if (D->isUnavailable())
-  return true;
-// A category implicitly has the availability of the interface.
-if (const 

[PATCH] D86828: [windows-itanium] make dllimport/export handling closer to MS behavior

2020-10-09 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb148ad426f8: [windows-itanium] make dllimport/export 
handling closer to MS behavior (authored by Ben Dunbobbin 
ben.dunbob...@sony.com).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86828/new/

https://reviews.llvm.org/D86828

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/Sema/dllimport.c
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

Index: clang/test/SemaCXX/dllimport.cpp
===
--- clang/test/SemaCXX/dllimport.cpp
+++ clang/test/SemaCXX/dllimport.cpp
@@ -1,8 +1,10 @@
-// RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DMS %s
-// RUN: %clang_cc1 -triple x86_64-win32   -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DMS %s
-// RUN: %clang_cc1 -triple i686-mingw32   -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DGNU %s
-// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DGNU %s
-// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
+// RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DMS %s
+// RUN: %clang_cc1 -triple x86_64-win32   -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DMS %s
+// RUN: %clang_cc1 -triple i686-mingw32   -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DGNU %s
+// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DGNU %s
+// RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
+// RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
+// RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Imported {};
@@ -55,7 +57,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
-#ifdef MS
+#if defined(MS) || defined(WI)
 // expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -66,7 +68,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 __declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}}
-#ifdef MS
+#if defined(MS) || defined(WI)
 // expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -77,7 +79,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}}
-#ifdef MS
+#if defined(MS) || defined(WI)
 // expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -88,7 +90,7 @@
 // expected-note@+2{{previous attribute is here}}
 #endif
 int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}}
-#ifdef MS
+#if defined(MS) || defined(WI)
 // expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -179,7 +181,7 @@
 #endif
 template 
 __declspec(dllimport) extern int ExternVarTmplDeclInit; // expected-note{{previous declaration is here}}
-#ifdef MS
+#if defined(MS) || defined(WI)
 // expected-warning@+5{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
 #else
 // expected-warning@+3{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
@@ -192,7 +194,7 @@
 #endif
 template 
 

[PATCH] D89025: [RISCV] Add -mtune support

2020-10-15 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcfa7094e49cf: [RISCV] Add -mtune support (authored by Kito 
Cheng kito.ch...@sifive.com).
Herald added a subscriber: NickHung.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89025/new/

https://reviews.llvm.org/D89025

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/riscv-cpus.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/include/llvm/Support/RISCVTargetParser.def
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/TargetParser.cpp
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Index: llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
===
--- llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -75,13 +75,16 @@
 const RISCVSubtarget *
 RISCVTargetMachine::getSubtargetImpl(const Function ) const {
   Attribute CPUAttr = F.getFnAttribute("target-cpu");
+  Attribute TuneAttr = F.getFnAttribute("tune-cpu");
   Attribute FSAttr = F.getFnAttribute("target-features");
 
   std::string CPU =
   CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
+  std::string TuneCPU =
+  TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
   std::string FS =
   FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
-  std::string Key = CPU + FS;
+  std::string Key = CPU + TuneCPU + FS;
   auto  = SubtargetMap[Key];
   if (!I) {
 // This needs to be done before we create a new subtarget since any
@@ -98,7 +101,7 @@
   }
   ABIName = ModuleTargetABI->getString();
 }
-I = std::make_unique(TargetTriple, CPU, FS, ABIName, *this);
+I = std::make_unique(TargetTriple, CPU, TuneCPU, FS, ABIName, *this);
   }
   return I.get();
 }
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -71,13 +71,15 @@
   /// Initializes using the passed in CPU and feature strings so that we can
   /// use initializer lists for subtarget initialization.
   RISCVSubtarget (const Triple ,
-  StringRef CPU, StringRef FS,
+  StringRef CPU,
+  StringRef TuneCPU,
+  StringRef FS,
   StringRef ABIName);
 
 public:
   // Initializes the data members to match that of the specified triple.
-  RISCVSubtarget(const Triple , StringRef CPU, StringRef FS,
- StringRef ABIName, const TargetMachine );
+  RISCVSubtarget(const Triple , StringRef CPU, StringRef TuneCPU,
+ StringRef FS, StringRef ABIName, const TargetMachine );
 
   // Parses features string setting specified subtarget options. The
   // definition of this function is auto-generated by tblgen.
Index: llvm/lib/Target/RISCV/RISCVSubtarget.cpp
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.cpp
+++ llvm/lib/Target/RISCV/RISCVSubtarget.cpp
@@ -30,13 +30,16 @@
 void RISCVSubtarget::anchor() {}
 
 RISCVSubtarget ::initializeSubtargetDependencies(
-const Triple , StringRef CPU, StringRef FS, StringRef ABIName) {
+const Triple , StringRef CPU, StringRef TuneCPU, StringRef FS, StringRef ABIName) {
   // Determine default and user-specified characteristics
   bool Is64Bit = TT.isArch64Bit();
   std::string CPUName = std::string(CPU);
+  std::string TuneCPUName = std::string(TuneCPU);
   if (CPUName.empty())
 CPUName = Is64Bit ? "generic-rv64" : "generic-rv32";
-  ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
+  if (TuneCPUName.empty())
+TuneCPUName = CPUName;
+  ParseSubtargetFeatures(CPUName, TuneCPUName, FS);
   if (Is64Bit) {
 XLenVT = MVT::i64;
 XLen = 64;
@@ -47,11 +50,12 @@
   return *this;
 }
 
-RISCVSubtarget::RISCVSubtarget(const Triple , StringRef CPU, StringRef FS,
+RISCVSubtarget::RISCVSubtarget(const Triple , StringRef CPU,
+   StringRef TuneCPU, StringRef FS,
StringRef ABIName, const TargetMachine )
-: RISCVGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
+: RISCVGenSubtargetInfo(TT, CPU, TuneCPU, FS),
   UserReservedRegister(RISCV::NUM_TARGET_REGS),
-  FrameLowering(initializeSubtargetDependencies(TT, CPU, FS, ABIName)),
+  FrameLowering(initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
   InstrInfo(*this), RegInfo(getHwMode()), 

[PATCH] D83448: [CodeGen] Emit destructor calls to destruct non-trivial C struct temporaries created by conditional and assignment operators

2020-10-23 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71e1a56de153: [CodeGen] Emit destructor calls to destruct 
non-trivial C struct (authored by ahatanak, committed by --local 
ahatan...@apple.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83448/new/

https://reviews.llvm.org/D83448

Files:
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/CodeGenObjC/strong-in-c-struct.m

Index: clang/test/CodeGenObjC/strong-in-c-struct.m
===
--- clang/test/CodeGenObjC/strong-in-c-struct.m
+++ clang/test/CodeGenObjC/strong-in-c-struct.m
@@ -95,12 +95,13 @@
 @end
 
 id g0;
+StrongSmall g1, g2;
 
+// CHECK: %[[STRUCT_STRONGSMALL:.*]] = type { i32, i8* }
 // CHECK: %[[STRUCT_STRONGOUTER:.*]] = type { %[[STRUCT_STRONG:.*]], i8*, double }
 // CHECK: %[[STRUCT_STRONG]] = type { %[[STRUCT_TRIVIAL:.*]], i8* }
 // CHECK: %[[STRUCT_TRIVIAL]] = type { [4 x i32] }
 // CHECK: %[[STRUCT_BLOCK_BYREF_T:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_T]]*, i32, i32, i8*, i8*, i8*, %[[STRUCT_STRONGOUTER]] }
-// CHECK: %[[STRUCT_STRONGSMALL:.*]] = type { i32, i8* }
 // CHECK: %[[STRUCT_STRONGBLOCK:.*]] = type { void ()* }
 // CHECK: %[[STRUCT_BITFIELD1:.*]] = type { i8, i8, i8*, i32, i8*, [3 x i32], i8*, double, i8, i8 }
 
@@ -900,4 +901,47 @@
   a = b;
 }
 
+// CHECK-LABEL: define i8* @test_conditional0(
+// CHECK: %[[TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
+
+// CHECK: %[[V1:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8**
+// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V1]], i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g2 to i8**))
+
+// CHECK: %[[V2:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8**
+// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V2]], i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g1 to i8**))
+
+// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8**
+// CHECK: call void @__destructor_8_s8(i8** %[[V5]])
+// CHECK: @llvm.objc.autoreleaseReturnValue
+
+id test_conditional0(int c) {
+  return (c ? g2 : g1).f1;
+}
+
+// CHECK-LABEL: define i8* @test_conditional1(
+// CHECK-NOT: call void @__destructor
+
+id test_conditional1(int c) {
+  calleeStrongSmall(c ? g2 : g1);
+}
+
+// CHECK-LABEL: define i8* @test_assignment0(
+// CHECK: %[[TMP:.*]] = alloca %[[STRUCT_STRONGSMALL]], align 8
+// CHECK: call void @__copy_assignment_8_8_t0w4_s8(i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g2 to i8**), i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g1 to i8**))
+// CHECK: %[[V0:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8**
+// CHECK: call void @__copy_constructor_8_8_t0w4_s8(i8** %[[V0]], i8** bitcast (%[[STRUCT_STRONGSMALL]]* @g2 to i8**))
+// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_STRONGSMALL]]* %[[TMP]] to i8**
+// CHECK: call void @__destructor_8_s8(i8** %[[V3]])
+
+id test_assignment0(void) {
+  return (g2 = g1).f1;
+}
+
+// CHECK-LABEL: define i8* @test_assignment1(
+// CHECK-NOT: call void @__destructor
+
+id test_assignment1(void) {
+  calleeStrongSmall(g2 = g1);
+}
+
 #endif /* USESTRUCT */
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1216,6 +1216,11 @@
 
   // Copy into the destination if the assignment isn't ignored.
   EmitFinalDestCopy(E->getType(), LHS);
+
+  if (!Dest.isIgnored() && !Dest.isExternallyDestructed() &&
+  E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
+CGF.pushDestroy(QualType::DK_nontrivial_c_struct, Dest.getAddress(),
+E->getType());
 }
 
 void AggExprEmitter::
@@ -1233,6 +1238,11 @@
 
   // Save whether the destination's lifetime is externally managed.
   bool isExternallyDestructed = Dest.isExternallyDestructed();
+  bool destructNonTrivialCStruct =
+  !isExternallyDestructed &&
+  E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct;
+  isExternallyDestructed |= destructNonTrivialCStruct;
+  Dest.setExternallyDestructed(isExternallyDestructed);
 
   eval.begin(CGF);
   CGF.EmitBlock(LHSBlock);
@@ -1254,6 +1264,10 @@
   Visit(E->getFalseExpr());
   eval.end(CGF);
 
+  if (destructNonTrivialCStruct)
+CGF.pushDestroy(QualType::DK_nontrivial_c_struct, Dest.getAddress(),
+E->getType());
+
   CGF.EmitBlock(ContBlock);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85157: [Sema] Add casting check for fixed to fixed point conversions

2020-08-07 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG351aac098543: [Sema] Add casting check for fixed to fixed 
point conversions (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Changed prior to commit:
  https://reviews.llvm.org/D85157?vs=283858=283887#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85157/new/

https://reviews.llvm.org/D85157

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-bad-function-cast.c


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast 
-ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -12,15 +12,20 @@
 _Bool bf(void);
 char *pf1(void);
 int *pf2(void);
+_Fract ff1(void);
 
 void
 foo(void)
 {
+
+  /* default, no cast, should always be ok */
+  ff1();
   /* Casts to void types are always OK.  */
   (void)vf();
   (void)if1();
   (void)cf();
   (const void)bf();
+  (void)ff1();
   /* Casts to the same type or similar types are OK.  */
   (int)if1();
   (long)if2();
@@ -32,6 +37,7 @@
   (_Bool)bf();
   (void *)pf1();
   (char *)pf2();
+  (_Fract) ff1();
   /* All following casts issue warning */
   (float)if1(); /* expected-warning {{cast from function call of type 'int' to 
non-matching type 'float'}} */
   (double)if2(); /* expected-warning {{cast from function call of type 'char' 
to non-matching type 'double'}} */
@@ -43,5 +49,7 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to 
non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 
'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of 
type 'int *' to non-matching type 'long'}} */
+  (_Fract) if1();  /* expected-warning{{cast from function call of 
type 'int' to non-matching type '_Fract'}} */
+  (int)ff1();  /* expected-warning{{cast from function call of 
type '_Fract' to non-matching type 'int'}} */
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType())
 return;
+  if (SrcType->isFixedPointType() && DestType->isFixedPointType())
+return;
 
   Self.Diag(SrcExpr.get()->getExprLoc(),
 diag::warn_bad_function_cast)


Index: clang/test/Sema/warn-bad-function-cast.c
===
--- clang/test/Sema/warn-bad-function-cast.c
+++ clang/test/Sema/warn-bad-function-cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -triple x86_64-unknown-unknown -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -ffixed-point -triple x86_64-unknown-unknown -verify
 // rdar://9103192
 
 void vf(void);
@@ -12,15 +12,20 @@
 _Bool bf(void);
 char *pf1(void);
 int *pf2(void);
+_Fract ff1(void);
 
 void
 foo(void)
 {
+
+  /* default, no cast, should always be ok */
+  ff1();
   /* Casts to void types are always OK.  */
   (void)vf();
   (void)if1();
   (void)cf();
   (const void)bf();
+  (void)ff1();
   /* Casts to the same type or similar types are OK.  */
   (int)if1();
   (long)if2();
@@ -32,6 +37,7 @@
   (_Bool)bf();
   (void *)pf1();
   (char *)pf2();
+  (_Fract) ff1();
   /* All following casts issue warning */
   (float)if1(); /* expected-warning {{cast from function call of type 'int' to non-matching type 'float'}} */
   (double)if2(); /* expected-warning {{cast from function call of type 'char' to non-matching type 'double'}} */
@@ -43,5 +49,7 @@
   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */
   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */
   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */
+  (_Fract) if1();  /* expected-warning{{cast from function call of type 'int' to non-matching type '_Fract'}} */
+  (int)ff1();  /* expected-warning{{cast from function call of type '_Fract' to non-matching type 'int'}} */
 }
 
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2657,6 +2657,8 @@
 return;
   if 

[PATCH] D85016: [clang-format] Add space between method modifier and a tuple return type in C#

2020-08-10 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5f104a809983: [clang-format] Add space between method 
modifier and a tuple return type in C# (authored by lbk, committed by Jonathan 
Coe jb...@google.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85016/new/

https://reviews.llvm.org/D85016

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -777,6 +777,20 @@
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
   verifyFormat(R"(char[ ,, ] rawCharArray = MakeCharacterGrid();)", Style);
+
+  // Method returning tuple
+  verifyFormat(R"(public (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(private (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(protected (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(virtual (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(extern (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(static (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(internal (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(abstract (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(sealed (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(override (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(async (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(unsafe (string name, int age) methodTuple() {})", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3115,6 +3115,16 @@
Keywords.kw_lock))
 return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements 
||
spaceRequiredBeforeParens(Right);
+
+// space between method modifier and opening parenthesis of a tuple return
+// type
+if (Left.isOneOf(tok::kw_public, tok::kw_private, tok::kw_protected,
+ tok::kw_virtual, tok::kw_extern, tok::kw_static,
+ Keywords.kw_internal, Keywords.kw_abstract,
+ Keywords.kw_sealed, Keywords.kw_override,
+ Keywords.kw_async, Keywords.kw_unsafe) &&
+Right.is(tok::l_paren))
+  return true;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -777,6 +777,20 @@
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
   verifyFormat(R"(char[ ,, ] rawCharArray = MakeCharacterGrid();)", Style);
+
+  // Method returning tuple
+  verifyFormat(R"(public (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(private (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(protected (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(virtual (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(extern (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(static (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(internal (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(abstract (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(sealed (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(override (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(async (string name, int age) methodTuple() {})", Style);
+  verifyFormat(R"(unsafe (string name, int age) methodTuple() {})", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3115,6 +3115,16 @@
Keywords.kw_lock))
 return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements ||
spaceRequiredBeforeParens(Right);
+
+// space between method modifier and opening parenthesis of a tuple return
+// type
+if (Left.isOneOf(tok::kw_public, tok::kw_private, tok::kw_protected,
+   

[PATCH] D83992: [ASTImporter] Add Visitor for TypedefNameDecl's

2020-07-28 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf761acfb1a73: [ASTImporter] Add Visitor for 
TypedefNameDecls (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83992/new/

https://reviews.llvm.org/D83992

Files:
  clang/lib/AST/ASTImporterLookupTable.cpp
  clang/test/Analysis/Inputs/ctu-import.c
  clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/ctu-implicit.c


Index: clang/test/Analysis/ctu-implicit.c
===
--- /dev/null
+++ clang/test/Analysis/ctu-implicit.c
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir2
+// RUN: %clang_cc1  \
+// RUN:   -emit-pch -o %t/ctudir2/ctu-import.c.ast %S/Inputs/ctu-import.c
+// RUN: cp %S/Inputs/ctu-import.c.externalDefMap.ast-dump.txt 
%t/ctudir2/externalDefMap.txt
+// RUN: %clang_cc1 -analyze \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config  display-ctu-progress=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir2 \
+// RUN:   -verify %s
+
+void clang_analyzer_eval(int);
+
+int testStaticImplicit(void);
+int func(void) {
+  int ret = testStaticImplicit();
+  clang_analyzer_eval(ret == 4); // expected-warning{{TRUE}}
+  return testStaticImplicit();
+}
Index: clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
@@ -0,0 +1 @@
+c:@F@testStaticImplicit ctu-import.c.ast
Index: clang/test/Analysis/Inputs/ctu-import.c
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-import.c
@@ -0,0 +1,15 @@
+
+// Use an internal, implicitly defined type, called by
+// a function imported for CTU. This should not crash.
+int foo(void);
+int foobar(int skip) {
+  __NSConstantString str = {.flags = 1};
+
+  if (str.flags >= 0)
+str.flags = 0;
+  return 4;
+}
+
+int testStaticImplicit(void) {
+  return foobar(3);
+}
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -22,6 +22,20 @@
 struct Builder : RecursiveASTVisitor {
   ASTImporterLookupTable 
   Builder(ASTImporterLookupTable ) : LT(LT) {}
+
+  bool VisitTypedefNameDecl(TypedefNameDecl *D) {
+QualType Ty = D->getUnderlyingType();
+Ty = Ty.getCanonicalType();
+if (const auto *RTy = dyn_cast(Ty)) {
+  LT.add(RTy->getAsRecordDecl());
+  // iterate over the field decls, adding them
+  for (auto *it : RTy->getAsRecordDecl()->fields()) {
+LT.add(it);
+  }
+}
+return true;
+  }
+
   bool VisitNamedDecl(NamedDecl *D) {
 LT.add(D);
 return true;


Index: clang/test/Analysis/ctu-implicit.c
===
--- /dev/null
+++ clang/test/Analysis/ctu-implicit.c
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir2
+// RUN: %clang_cc1  \
+// RUN:   -emit-pch -o %t/ctudir2/ctu-import.c.ast %S/Inputs/ctu-import.c
+// RUN: cp %S/Inputs/ctu-import.c.externalDefMap.ast-dump.txt %t/ctudir2/externalDefMap.txt
+// RUN: %clang_cc1 -analyze \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config  display-ctu-progress=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir2 \
+// RUN:   -verify %s
+
+void clang_analyzer_eval(int);
+
+int testStaticImplicit(void);
+int func(void) {
+  int ret = testStaticImplicit();
+  clang_analyzer_eval(ret == 4); // expected-warning{{TRUE}}
+  return testStaticImplicit();
+}
Index: clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
@@ -0,0 +1 @@
+c:@F@testStaticImplicit ctu-import.c.ast
Index: clang/test/Analysis/Inputs/ctu-import.c
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-import.c
@@ -0,0 +1,15 @@
+
+// Use an internal, implicitly defined type, called by
+// a function imported for CTU. This should not crash.
+int foo(void);
+int foobar(int skip) {
+  __NSConstantString str = {.flags = 1};
+
+  if (str.flags >= 0)
+str.flags = 0;
+  return 4;
+}
+
+int testStaticImplicit(void) {
+  return foobar(3);
+}
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ 

[Differential] D83970: [ASTImporter] Refactor ASTImporter to support custom downstream tests

2020-07-21 Thread Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG20157410862d: [ASTImporter] Refactor ASTImporter to support 
custom downstream tests (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83970/new/


  https://reviews.llvm.org/D83970

Files:
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -18,7 +18,6 @@
 #include "gtest/gtest.h"
 
 #include "ASTImporterFixtures.h"
-#include "MatchVerifier.h"
 
 namespace clang {
 namespace ast_matchers {
@@ -27,230 +26,6 @@
 using internal::BindableMatcher;
 using llvm::StringMap;
 
-// Base class for those tests which use the family of `testImport` functions.
-class TestImportBase
-: public CompilerOptionSpecificTest,
-  public ::testing::WithParamInterface> {
-
-  template 
-  llvm::Expected importNode(ASTUnit *From, ASTUnit *To,
-  ASTImporter , NodeType Node) {
-ASTContext  = To->getASTContext();
-
-// Add 'From' file to virtual file system so importer can 'find' it
-// while importing SourceLocations. It is safe to add same file multiple
-// times - it just isn't replaced.
-StringRef FromFileName = From->getMainFileName();
-createVirtualFileIfNeeded(To, FromFileName,
-  From->getBufferForFile(FromFileName));
-
-auto Imported = Importer.Import(Node);
-
-if (Imported) {
-  // This should dump source locations and assert if some source locations
-  // were not imported.
-  SmallString<1024> ImportChecker;
-  llvm::raw_svector_ostream ToNothing(ImportChecker);
-  ToCtx.getTranslationUnitDecl()->print(ToNothing);
-
-  // This traverses the AST to catch certain bugs like poorly or not
-  // implemented subtrees.
-  (*Imported)->dump(ToNothing);
-}
-
-return Imported;
-  }
-
-  template 
-  testing::AssertionResult
-  testImport(const std::string ,
- const std::vector ,
- const std::string , const std::vector ,
- MatchVerifier ,
- const BindableMatcher ,
- const BindableMatcher ) {
-const char *const InputFileName = "input.cc";
-const char *const OutputFileName = "output.cc";
-
-std::unique_ptr FromAST = tooling::buildASTFromCodeWithArgs(
- FromCode, FromArgs, InputFileName),
- ToAST = tooling::buildASTFromCodeWithArgs(
- ToCode, ToArgs, OutputFileName);
-
-ASTContext  = FromAST->getASTContext(),
-= ToAST->getASTContext();
-
-ASTImporter Importer(ToCtx, ToAST->getFileManager(), FromCtx,
- FromAST->getFileManager(), false);
-
-auto FoundNodes = match(SearchMatcher, FromCtx);
-if (FoundNodes.size() != 1)
-  return testing::AssertionFailure()
- << "Multiple potential nodes were found!";
-
-auto ToImport = selectFirst(DeclToImportID, FoundNodes);
-if (!ToImport)
-  return testing::AssertionFailure() << "Node type mismatch!";
-
-// Sanity check: the node being imported should match in the same way as
-// the result node.
-BindableMatcher WrapperMatcher(VerificationMatcher);
-EXPECT_TRUE(Verifier.match(ToImport, WrapperMatcher));
-
-auto Imported = importNode(FromAST.get(), ToAST.get(), Importer, ToImport);
-if (!Imported) {
-  std::string ErrorText;
-  handleAllErrors(
-  Imported.takeError(),
-  [](const ImportError ) { ErrorText = Err.message(); });
-  return testing::AssertionFailure()
- << "Import failed, error: \"" << ErrorText << "\"!";
-}
-
-return Verifier.match(*Imported, WrapperMatcher);
-  }
-
-  template 
-  testing::AssertionResult
-  testImport(const std::string ,
- const std::vector ,
- const std::string , const std::vector ,
- MatchVerifier ,
- const BindableMatcher ) {
-return testImport(
-FromCode, FromArgs, ToCode, ToArgs, Verifier,
-translationUnitDecl(
-has(namedDecl(hasName(DeclToImportID)).bind(DeclToImportID))),
-VerificationMatcher);
-  }
-
-protected:
-  std::vector getExtraArgs() const override { return GetParam(); }
-
-public:
-
-  /// Test how AST node named "declToImport" located in the translation unit
-  /// of "FromCode" virtual file is imported to "ToCode" virtual file.
-  /// The verification is done by running AMatcher over the imported node.
-  template 
-  void 

[PATCH] D90299: [windows-itanium] handle dllimport/export code paths separately and share with PS4

2020-11-30 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd5aaf6021476: [windows-itanium] handle dllimport/export code 
paths separately and share with… (authored by Ben Dunbobbin 
ben.dunbob...@sony.com).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90299/new/

https://reviews.llvm.org/D90299

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CodeGenCXX/dllexport-vtable-thunks.cpp
  clang/test/CodeGenCXX/windows-implicit-dllexport-template-specialization.cpp
  clang/test/CodeGenCXX/windows-itanium-dllexport.cpp
  clang/test/Sema/dllimport.c
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

Index: clang/test/SemaCXX/dllimport.cpp
===
--- clang/test/SemaCXX/dllimport.cpp
+++ clang/test/SemaCXX/dllimport.cpp
@@ -5,6 +5,8 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Imported {};
Index: clang/test/SemaCXX/dllexport.cpp
===
--- clang/test/SemaCXX/dllexport.cpp
+++ clang/test/SemaCXX/dllexport.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DWI %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fdeclspec  -verify -std=c++1y -Wunsupported-dll-base-class-template -DWI %s
 
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Exported {};
Index: clang/test/Sema/dllimport.c
===
--- clang/test/Sema/dllimport.c
+++ clang/test/Sema/dllimport.c
@@ -5,6 +5,8 @@
 // RUN: %clang_cc1 -triple aarch64-win32  -fsyntax-only -fms-extensions -verify -std=c99 -DMS %s
 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c99 -DWI %s
 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c11 -DWI %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fms-extensions -verify -std=c11 -DWI %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4-fsyntax-only -fms-extensions -verify -std=c99 -DWI %s
 
 // Invalid usage.
 __declspec(dllimport) typedef int typedef1;
Index: clang/test/CodeGenCXX/windows-itanium-dllexport.cpp
===
--- clang/test/CodeGenCXX/windows-itanium-dllexport.cpp
+++ clang/test/CodeGenCXX/windows-itanium-dllexport.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -emit-llvm -triple i686-windows-itanium -fdeclspec %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple i686-windows-itanium -fdeclspec %s -o - | FileCheck %s --check-prefixes=CHECK,WI
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-scei-ps4 -fdeclspec %s -o - | FileCheck %s --check-prefixes=CHECK,PS4
 
 #define JOIN2(x, y) x##y
 #define JOIN(x, y) JOIN2(x, y)
@@ -25,14 +26,18 @@
 extern template class c;
 template class __declspec(dllexport) c;
 
-// CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIcEaSERKS0_
-// CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIcE1fEv
+// WI: define {{.*}} dllexport {{.*}} @_ZN1cIcEaSERKS0_
+// WI: define {{.*}} dllexport {{.*}} @_ZN1cIcE1fEv
+// PS4-NOT: @_ZN1cIcEaSERKS0_
+// PS4: define weak_odr void @_ZN1cIcE1fEv
 
 c g;
 template class __declspec(dllexport) c;
 
-// CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIdEaSERKS0_
-// CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIdE1fEv
+// WI: define {{.*}} dllexport {{.*}} @_ZN1cIdEaSERKS0_
+// WI: define {{.*}} dllexport {{.*}} @_ZN1cIdE1fEv
+// PS4-NOT: @_ZN1cIdEaSERKS0_
+// PS4: define weak_odr void @_ZN1cIdE1fEv
 
 template 
 struct outer {

[PATCH] D91779: [Clang][-fvisibility-from-dllstorageclass] Set DSO Locality from final visibility

2020-11-23 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe42021d5cc25: [Clang][-fvisibility-from-dllstorageclass] Set 
DSO Locality from final… (authored by Ben Dunbobbin 
ben.dunbob...@sony.com).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91779/new/

https://reviews.llvm.org/D91779

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/visibility-dllstorageclass.cpp

Index: clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
===
--- clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
+++ clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
@@ -5,12 +5,14 @@
 
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \
 // RUN: -fvisibility hidden \
+// RUN: -fapply-global-visibility-to-externs \
 // RUN: -fvisibility-from-dllstorageclass \
 // RUN: -x c++ %s -S -emit-llvm -o - | \
-// RUN:   FileCheck %s --check-prefixes=DEFAULT
+// RUN:   FileCheck %s --check-prefixes=DEFAULTS
 
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \
 // RUN: -fvisibility hidden \
+// RUN: -fapply-global-visibility-to-externs \
 // RUN: -fvisibility-from-dllstorageclass \
 // RUN: -fvisibility-dllexport=hidden \
 // RUN: -fvisibility-nodllstorageclass=protected \
@@ -19,45 +21,78 @@
 // RUN: -x c++  %s -S -emit-llvm -o - | \
 // RUN:   FileCheck %s --check-prefixes=EXPLICIT
 
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -fdeclspec \
+// RUN: -fvisibility hidden \
+// RUN: -fapply-global-visibility-to-externs \
+// RUN: -fvisibility-from-dllstorageclass \
+// RUN: -fvisibility-dllexport=default \
+// RUN: -fvisibility-nodllstorageclass=default \
+// RUN: -fvisibility-externs-dllimport=default \
+// RUN: -fvisibility-externs-nodllstorageclass=default \
+// RUN: -x c++  %s -S -emit-llvm -o - | \
+// RUN:   FileCheck %s --check-prefixes=ALL_DEFAULT
+
 // Local
 static void l() {}
 void use_locals(){l();}
-// DEFAULT-DAG: define internal void @_ZL1lv()
+// DEFAULTS-DAG: define internal void @_ZL1lv()
 // EXPLICIT-DAG: define internal void @_ZL1lv()
+// ALL_DEFAULT-DAG: define internal void @_ZL1lv()
 
 // Function
 void f() {}
 void __declspec(dllexport) exported_f() {}
-// DEFAULT-DAG: define hidden void @_Z1fv()
-// DEFAULT-DAG: define dso_local void @_Z10exported_fv()
+// DEFAULTS-DAG: define hidden void @_Z1fv()
+// DEFAULTS-DAG: define void @_Z10exported_fv()
 // EXPLICIT-DAG: define protected void @_Z1fv()
 // EXPLICIT-DAG: define hidden void @_Z10exported_fv()
+// ALL_DEFAULT-DAG: define void @_Z1fv()
+// ALL_DEFAULT-DAG: define void @_Z10exported_fv()
 
 // Variable
 int d = 123;
 __declspec(dllexport) int exported_d = 123;
-// DEFAULT-DAG: @d = hidden global
-// DEFAULT-DAG: @exported_d = dso_local global
+// DEFAULTS-DAG: @d = hidden global
+// DEFAULTS-DAG: @exported_d = global
 // EXPLICIT-DAG: @d = protected global
 // EXPLICIT-DAG: @exported_d = hidden global
+// ALL_DEFAULT-DAG: @d = global
+// ALL_DEFAULT-DAG: @exported_d = global
 
 // Alias
 extern "C" void aliased() {}
 void a() __attribute__((alias("aliased")));
 void __declspec(dllexport) a_exported() __attribute__((alias("aliased")));
-// DEFAULT-DAG: @_Z1av = hidden alias
-// DEFAULT-DAG: @_Z10a_exportedv = dso_local alias
+// DEFAULTS-DAG: @_Z1av = hidden alias
+// DEFAULTS-DAG: @_Z10a_exportedv = alias
 // EXPLICIT-DAG: @_Z1av = protected alias
 // EXPLICIT-DAG: @_Z10a_exportedv = hidden alias
+// ALL_DEFAULT-DAG: @_Z1av = alias
+// ALL_DEFAULT-DAG: @_Z10a_exportedv = alias
 
 // Declaration
 extern void e();
 extern void __declspec(dllimport) imported_e();
-void use_declarations(){e(); imported_e();}
-// DEFAULT-DAG: declare hidden void @_Z1ev()
-// DEFAULT-DAG: declare void @_Z10imported_ev()
+// DEFAULTS-DAG: declare hidden void @_Z1ev()
+// DEFAULTS-DAG: declare void @_Z10imported_ev()
 // EXPLICIT-DAG: declare protected void @_Z1ev()
 // EXPLICIT-DAG: declare hidden void @_Z10imported_ev()
+// ALL_DEFAULT-DAG: declare void @_Z1ev()
+// ALL_DEFAULT-DAG: declare void @_Z10imported_ev()
+
+// Weak Declaration
+__attribute__((weak))
+extern void w();
+__attribute__((weak))
+extern void __declspec(dllimport) imported_w();
+// DEFAULTS-DAG: declare extern_weak hidden void @_Z1wv()
+// DEFAULTS-DAG: declare extern_weak void @_Z10imported_wv()
+// EXPLICIT-DAG: declare extern_weak protected void @_Z1wv()
+// EXPLICIT-DAG: declare extern_weak hidden void @_Z10imported_wv()
+// ALL_DEFAULT-DAG: declare extern_weak void @_Z1wv()
+// ALL_DEFAULT-DAG: declare extern_weak void @_Z10imported_wv()
+
+void use_declarations(){e(); imported_e(); w(); imported_w();}
 
 // Show that -fvisibility-from-dllstorageclass overrides the effect of visibility annotations.
 
@@ -65,12 +100,12 @@
   virtual void foo();
 };
 void 

[PATCH] D89970: Add the ability to map DLL storage class to visibility

2020-11-02 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG415f7ee88369: [Clang] Add the ability to map DLL storage 
class to visibility (authored by Ben Dunbobbin ben.dunbob...@sony.com).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D89970?vs=301803=302305#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89970/new/

https://reviews.llvm.org/D89970

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/PS4CPU.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
  clang/test/Driver/ps4-visibility-dllstorageclass.c
  clang/test/Driver/visibility-dllstorageclass.c

Index: clang/test/Driver/visibility-dllstorageclass.c
===
--- /dev/null
+++ clang/test/Driver/visibility-dllstorageclass.c
@@ -0,0 +1,87 @@
+// Check behaviour of -fvisibility-from-dllstorageclass options
+
+// RUN: %clang -target x86_64-unknown-windows-itanium -fdeclspec \
+// RUN: -Werror -S -### %s 2>&1 | \
+// RUN:   FileCheck %s \
+// RUN: --implicit-check-not=-fvisibility-from-dllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-dllexport \
+// RUN: --implicit-check-not=-fvisibility-nodllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-externs-dllimport \
+// RUN: --implicit-check-not=-fvisibility-externs-nodllstorageclass
+
+// RUN: %clang -target x86_64-unknown-windows-itanium -fdeclspec \
+// RUN: -fvisibility-from-dllstorageclass \
+// RUN: -fno-visibility-from-dllstorageclass \
+// RUN: -Werror -S -### %s 2>&1 | \
+// RUN:   FileCheck %s \
+// RUN: --implicit-check-not=-fvisibility-from-dllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-dllexport \
+// RUN: --implicit-check-not=-fvisibility-nodllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-externs-dllimport \
+// RUN: --implicit-check-not=-fvisibility-externs-nodllstorageclass
+
+// RUN: %clang -target x86_64-unknown-windows-itanium -fdeclspec \
+// RUN: -fno-visibility-from-dllstorageclass \
+// RUN: -fvisibility-from-dllstorageclass \
+// RUN: -Werror -S -### %s 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=SET \
+// RUN: --implicit-check-not=-fvisibility-from-dllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-dllexport \
+// RUN: --implicit-check-not=-fvisibility-nodllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-externs-dllimport \
+// RUN: --implicit-check-not=-fvisibility-externs-nodllstorageclass
+
+// RUN: %clang -target x86_64-unknown-windows-itanium -fdeclspec \
+// RUN: -fvisibility-dllexport=hidden \
+// RUN: -fvisibility-nodllstorageclass=protected \
+// RUN: -fvisibility-externs-dllimport=hidden \
+// RUN: -fvisibility-externs-nodllstorageclass=protected \
+// RUN: -S -### %s 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=UNUSED \
+// RUN: --implicit-check-not=-fvisibility-from-dllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-dllexport \
+// RUN: --implicit-check-not=-fvisibility-nodllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-externs-dllimport \
+// RUN: --implicit-check-not=-fvisibility-externs-nodllstorageclass \
+// RUN: --implicit-check-not=error: \
+// RUN: --implicit-check-not=warning:
+
+// RUN: %clang -target x86_64-unknown-windows-itanium -fdeclspec \
+// RUN: -fno-visibility-from-dllstorageclass \
+// RUN: -fvisibility-dllexport=hidden \
+// RUN: -fvisibility-nodllstorageclass=protected \
+// RUN: -fvisibility-externs-dllimport=hidden \
+// RUN: -fvisibility-externs-nodllstorageclass=protected \
+// RUN: -S -### %s 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=UNUSED \
+// RUN: --implicit-check-not=-fvisibility-from-dllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-dllexport \
+// RUN: --implicit-check-not=-fvisibility-nodllstorageclass \
+// RUN: --implicit-check-not=-fvisibility-externs-dllimport \
+// RUN: --implicit-check-not=-fvisibility-externs-nodllstorageclass \
+// RUN: --implicit-check-not=error: \
+// RUN: --implicit-check-not=warning:
+
+// UNUSED:  clang: warning: argument unused during compilation: '-fvisibility-dllexport=hidden'
+// UNUSED-NEXT: clang: warning: argument unused during compilation: '-fvisibility-nodllstorageclass=protected'
+// UNUSED-NEXT: clang: warning: argument unused during compilation: '-fvisibility-externs-dllimport=hidden'
+// UNUSED-NEXT: clang: warning: argument unused during compilation: '-fvisibility-externs-nodllstorageclass=protected'
+
+// RUN: %clang -target x86_64-unknown-windows-itanium -fdeclspec \
+// 

[PATCH] D90442: [PS4] Support dllimport/export attributes

2020-11-02 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGff2e24a741e4: [PS4] Support dllimport/export attributes 
(authored by Ben Dunbobbin ben.dunbob...@sony.com).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90442/new/

https://reviews.llvm.org/D90442

Files:
  clang/include/clang/Basic/Attr.td
  clang/test/CodeGen/ps4-dllimport-dllexport.c
  llvm/include/llvm/ADT/Triple.h

Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -782,6 +782,9 @@
 return isOSBinFormatXCOFF() || isWasm();
   }
 
+  /// Tests if the environment supports dllimport/export annotations.
+  bool hasDLLImportExport() const { return isOSWindows() || isPS4CPU(); }
+
   /// @}
   /// @name Mutators
   /// @{
Index: clang/test/CodeGen/ps4-dllimport-dllexport.c
===
--- /dev/null
+++ clang/test/CodeGen/ps4-dllimport-dllexport.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 \
+// RUN: -triple x86_64-scei-ps4 \
+// RUN: -fdeclspec \
+// RUN: -Werror \
+// RUN: -emit-llvm %s -o - | \
+// RUN:   FileCheck %s
+
+__declspec(dllexport) int export_int;
+
+__declspec(dllimport) int import_int;
+
+__declspec(dllexport) void export_declared_function();
+
+__declspec(dllexport) void export_implemented_function() {
+}
+
+__declspec(dllimport) void import_function(int);
+
+void call_imported_function() {
+  export_declared_function();
+  return import_function(import_int);
+}
+
+// CHECK-DAG: @import_int = external dllimport
+// CHECK-DAG: @export_int = dllexport global i32 0
+// CHECK-DAG: define dllexport void @export_implemented_function()
+// CHECK-DAG: declare dllimport void @import_function(i32)
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -368,8 +368,8 @@
 def TargetX86 : TargetArch<["x86"]>;
 def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
 def TargetWebAssembly : TargetArch<["wasm32", "wasm64"]>;
-def TargetWindows : TargetArch<["x86", "x86_64", "arm", "thumb", "aarch64"]> {
-  let OSes = ["Win32"];
+def TargetHasDLLImportExport : TargetSpec {
+  let CustomCode = [{ Target.getTriple().hasDLLImportExport() }];
 }
 def TargetItaniumCXXABI : TargetSpec {
   let CustomCode = [{ Target.getCXXABI().isItaniumFamily() }];
@@ -3144,24 +3144,24 @@
   let SimpleHandler = 1;
 }
 
-def DLLExport : InheritableAttr, TargetSpecificAttr {
+def DLLExport : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"dllexport">, GCC<"dllexport">];
   let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
   let Documentation = [DLLExportDocs];
 }
 
-def DLLExportStaticLocal : InheritableAttr, TargetSpecificAttr {
+def DLLExportStaticLocal : InheritableAttr, TargetSpecificAttr {
   // This attribute is used internally only when -fno-dllexport-inlines is
-  // passed. This attribute is added to inline function of class having
-  // dllexport attribute. And if the function has static local variables, this
-  // attribute is used to whether the variables are exported or not. Also if
-  // function has local static variables, the function is dllexported too.
+  // passed. This attribute is added to inline functions of a class having the
+  // dllexport attribute. If the function has static local variables, this
+  // attribute is used to determine whether the variables are exported or not. If
+  // the function has local static variables, the function is dllexported too.
   let Spellings = [];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [Undocumented];
 }
 
-def DLLImport : InheritableAttr, TargetSpecificAttr {
+def DLLImport : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
   let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>;
   let Documentation = [DLLImportDocs];
@@ -3177,11 +3177,11 @@
   }];
 }
 
-def DLLImportStaticLocal : InheritableAttr, TargetSpecificAttr {
+def DLLImportStaticLocal : InheritableAttr, TargetSpecificAttr {
   // This attribute is used internally only when -fno-dllexport-inlines is
-  // passed. This attribute is added to inline function of class having
-  // dllimport attribute. And if the function has static local variables, this
-  // attribute is used to whether the variables are imported or not.
+  // passed. This attribute is added to inline functions of a class having the
+  // dllimport attribute. If the function has static local variables, this
+  // attribute is used to determine whether the variables are imported or not.
   let Spellings = [];
   let Subjects = SubjectList<[Function]>;
   let Documentation = 

[PATCH] D71714: [Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array item

2021-02-03 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe48f444751cf: [Sema] Fix -Warray-bounds false negative when 
casting an out-of-bounds array… (authored by ilya, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71714/new/

https://reviews.llvm.org/D71714

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Parser/cxx-ambig-decl-expr.cpp
  clang/test/SemaCXX/array-bounds.cpp

Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -27,7 +27,7 @@
 };
 
 void f1(int a[1]) {
-  int val = a[3]; // no warning for function argumnet
+  int val = a[3]; // no warning for function argument
 }
 
 void f2(const int ()[2]) { // expected-note {{declared here}}
@@ -133,7 +133,7 @@
 
 int test_sizeof_as_condition(int flag) {
   int arr[2] = { 0, 0 }; // expected-note {{array 'arr' declared here}}
-  if (flag) 
+  if (flag)
 return sizeof(char) != sizeof(char) ? arr[2] : arr[1];
   return sizeof(char) == sizeof(char) ? arr[2] : arr[1]; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
 }
@@ -241,7 +241,7 @@
 }
 
 int test_pr11007_aux(const char * restrict, ...);
-  
+
 // Test checking with varargs.
 void test_pr11007() {
   double a[5]; // expected-note {{array 'a' declared here}}
@@ -320,3 +320,33 @@
   arr[1] = 0; // expected-warning {{array index 1 is past the end of the array (which contains 1 element)}}
 }
 } // namespace var_template_array
+
+namespace PR44343 {
+  const unsigned int array[2] = {0, 1}; // expected-note 5{{array 'array' declared here}}
+
+  const int i1 = (const int)array[2]; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  const int i2 = static_cast(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  const int  = reinterpret_cast(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  unsigned int  = const_cast(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  int i5 = int(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  const unsigned int *i6 = &(1 > 0 ? array[2] : array[1]); // no warning for one-past-end element's address retrieval
+
+  // Test dynamic cast
+  struct Base {
+virtual ~Base();
+  };
+  struct Derived : Base {
+  };
+  Base baseArr[2]; // expected-note {{array 'baseArr' declared here}}
+  Derived *d1 = dynamic_cast([2]); // FIXME: Should actually warn because dynamic_cast accesses the vptr
+  Derived  = dynamic_cast(baseArr[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+
+  // Test operator `&` in combination with operators `.` and `->`
+  struct A {
+int n;
+  };
+  A a[2]; // expected-note {{array 'a' declared here}}
+  int *n = [2].n; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  A *aPtr[2]; // expected-note {{array 'aPtr' declared here}}
+  int *n2 = [2]->n; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+}
Index: clang/test/Parser/cxx-ambig-decl-expr.cpp
===
--- clang/test/Parser/cxx-ambig-decl-expr.cpp
+++ clang/test/Parser/cxx-ambig-decl-expr.cpp
@@ -24,7 +24,7 @@
 
   // This is array indexing not an array declarator because a comma expression
   // is not syntactically a constant-expression.
-  int(x[1,1]); // expected-warning 2{{unused}}
+  int(x[1,0]); // expected-warning 2{{unused}}
 
   // This is array indexing not an array declaration because a braced-init-list
   // is not syntactically a constant-expression.
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14387,62 +14387,63 @@
 PDiag(diag::note_array_declared_here) << ND);
 }
 
-void Sema::CheckArrayAccess(const Expr *expr) {
-  int AllowOnePastEnd = 0;
-  while (expr) {
-expr = expr->IgnoreParenImpCasts();
-switch (expr->getStmtClass()) {
-  case Stmt::ArraySubscriptExprClass: {
-const ArraySubscriptExpr *ASE = cast(expr);
-CheckArrayAccess(ASE->getBase(), ASE->getIdx(), ASE,
- AllowOnePastEnd > 0);
-expr = ASE->getBase();
-break;
-  }
-  case Stmt::MemberExprClass: {
-expr = cast(expr)->getBase();
-break;
-  }
-  case Stmt::OMPArraySectionExprClass: {
-const OMPArraySectionExpr *ASE = cast(expr);
-   

[PATCH] D103707: [AIX] Define __STDC_NO_ATOMICS__ and __STDC_NO_THREADS__ predefined macros

2021-06-07 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe6629be31e67: [AIX] Define __STDC_NO_ATOMICS__ and 
__STDC_NO_THREADS__ predefined macros (authored by Jake-Egan, committed by 
cbowler cbow...@pcoral03.rtp.raleigh.ibm.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103707/new/

https://reviews.llvm.org/D103707

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init-ppc.c


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -723,6 +723,16 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-AIX-NOTHREADSAFE %s
 // PPC-AIX-NOTHREADSAFE-NOT:#define _THREAD_SAFE 1
 
+// RUN: %clang_cc1 -x c -std=c11 -E -dM -ffreestanding 
-triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck 
-match-full-lines -check-prefix PPC-AIX-STDC %s
+// RUN: %clang_cc1 -x c -std=gnu11 -E -dM -ffreestanding 
-triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck 
-match-full-lines -check-prefix PPC-AIX-STDC %s
+// RUN: %clang_cc1 -x c -std=c17 -E -dM -ffreestanding 
-triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck 
-match-full-lines -check-prefix PPC-AIX-STDC %s
+// PPC-AIX-STDC:#define __STDC_NO_ATOMICS__ 1
+// PPC-AIX-STDC:#define __STDC_NO_THREADS__ 1
+
+// RUN: %clang_cc1 -x c -std=c99 -E -dM -ffreestanding 
-triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck 
-match-full-lines -check-prefix PPC-AIX-STDC-N %s
+// PPC-AIX-STDC-N-NOT:#define __STDC_NO_ATOMICS__ 1
+// PPC-AIX-STDC-N-NOT:#define __STDC_NO_THREADS__ 1
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-LINUX %s
 //
 // PPC-LINUX:#define _ARCH_PPC 1
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -676,6 +676,11 @@
 
 Builder.defineMacro("_AIX");
 
+if (LangStandard::getLangStandardForKind(Opts.LangStd).isC11()) {
+  Builder.defineMacro("__STDC_NO_ATOMICS__");
+  Builder.defineMacro("__STDC_NO_THREADS__");
+}
+
 if (Opts.EnableAIXExtendedAltivecABI)
   Builder.defineMacro("__EXTABI__");
 


Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -723,6 +723,16 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-NOTHREADSAFE %s
 // PPC-AIX-NOTHREADSAFE-NOT:#define _THREAD_SAFE 1
 
+// RUN: %clang_cc1 -x c -std=c11 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-STDC %s
+// RUN: %clang_cc1 -x c -std=gnu11 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-STDC %s
+// RUN: %clang_cc1 -x c -std=c17 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-STDC %s
+// PPC-AIX-STDC:#define __STDC_NO_ATOMICS__ 1
+// PPC-AIX-STDC:#define __STDC_NO_THREADS__ 1
+
+// RUN: %clang_cc1 -x c -std=c99 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-STDC-N %s
+// PPC-AIX-STDC-N-NOT:#define __STDC_NO_ATOMICS__ 1
+// PPC-AIX-STDC-N-NOT:#define __STDC_NO_THREADS__ 1
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-LINUX %s
 //
 // PPC-LINUX:#define _ARCH_PPC 1
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -676,6 +676,11 @@
 
 Builder.defineMacro("_AIX");
 
+if (LangStandard::getLangStandardForKind(Opts.LangStd).isC11()) {
+  Builder.defineMacro("__STDC_NO_ATOMICS__");
+  Builder.defineMacro("__STDC_NO_THREADS__");
+}
+
 if (Opts.EnableAIXExtendedAltivecABI)
   Builder.defineMacro("__EXTABI__");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104774: [clang-format] Fix a bug that indents else-comment-if incorrectly

2021-06-23 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGca7f47158581: [clang-format] Fix a bug that indents 
else-comment-if incorrectly (authored by owenca 
owe...@users.noreply.github.com).

Changed prior to commit:
  https://reviews.llvm.org/D104774?vs=353909=353933#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104774/new/

https://reviews.llvm.org/D104774

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1181,6 +1181,13 @@
"  g();\n"
"else\n"
"  h();");
+  verifyFormat("if (a)\n"
+   "  f();\n"
+   "else // comment\n"
+   "  if (b) {\n"
+   "g();\n"
+   "h();\n"
+   "  }");
   verifyFormat("if constexpr (a)\n"
"  f();\n"
"else if constexpr (b)\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2021,7 +2021,15 @@
   parseBlock(/*MustBeDeclaration=*/false);
   addUnwrappedLine();
 } else if (FormatTok->Tok.is(tok::kw_if)) {
+  FormatToken *Previous = AllTokens[Tokens->getPosition() - 1];
+  bool PrecededByComment = Previous->is(tok::comment);
+  if (PrecededByComment) {
+addUnwrappedLine();
+++Line->Level;
+  }
   parseIfThenElse();
+  if (PrecededByComment)
+--Line->Level;
 } else {
   addUnwrappedLine();
   ++Line->Level;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1181,6 +1181,13 @@
"  g();\n"
"else\n"
"  h();");
+  verifyFormat("if (a)\n"
+   "  f();\n"
+   "else // comment\n"
+   "  if (b) {\n"
+   "g();\n"
+   "h();\n"
+   "  }");
   verifyFormat("if constexpr (a)\n"
"  f();\n"
"else if constexpr (b)\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2021,7 +2021,15 @@
   parseBlock(/*MustBeDeclaration=*/false);
   addUnwrappedLine();
 } else if (FormatTok->Tok.is(tok::kw_if)) {
+  FormatToken *Previous = AllTokens[Tokens->getPosition() - 1];
+  bool PrecededByComment = Previous->is(tok::comment);
+  if (PrecededByComment) {
+addUnwrappedLine();
+++Line->Level;
+  }
   parseIfThenElse();
+  if (PrecededByComment)
+--Line->Level;
 } else {
   addUnwrappedLine();
   ++Line->Level;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105378: [dfsan][NFC] Add Origin Tracking into doc

2021-07-07 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71dc0f1c02cd: [dfsan][NFC] Add Origin Tracking into doc 
(authored by Jianzhou Zhao jianzho...@google.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105378/new/

https://reviews.llvm.org/D105378

Files:
  clang/docs/DataFlowSanitizer.rst


Index: clang/docs/DataFlowSanitizer.rst
===
--- clang/docs/DataFlowSanitizer.rst
+++ clang/docs/DataFlowSanitizer.rst
@@ -191,6 +191,44 @@
 return 0;
   }
 
+Origin Tracking
+===
+
+DataFlowSanitizer can track origins of labeled values. This feature is enabled 
by
+``-mllvm -dfsan-track-origins=1``. For example,
+
+.. code-block:: console
+
+% cat test.cc
+#include 
+#include 
+
+int main(int argc, char** argv) {
+  int i = 0;
+  dfsan_set_label(i_label, , sizeof(i));
+  int j = i + 1;
+  dfsan_print_origin_trace(, "A flow from i to j");
+  return 0;
+}
+
+% clang++ -fsanitize=dataflow -mllvm -dfsan-track-origins=1 
-fno-omit-frame-pointer -g -O2 test.cc
+% ./a.out
+Taint value 0x1 (at 0x7ffd42bf415c) origin tracking (A flow from i to j)
+Origin value: 0x1391, Taint value was stored to memory at
+  #0 0x55676db85a62 in main test.cc:7:7
+  #1 0x7f0083611bbc in __libc_start_main libc-start.c:285
+
+Origin value: 0x9e1, Taint value was created at
+  #0 0x55676db85a08 in main test.cc:6:3
+  #1 0x7f0083611bbc in __libc_start_main libc-start.c:285
+
+By ``-mllvm -dfsan-track-origins=1`` DataFlowSanitizer collects only
+intermediate stores a labeled value went through. Origin tracking slows down
+program execution by a factor of 2x on top of the usual DataFlowSanitizer
+slowdown and increases memory overhead by 1x. By ``-mllvm 
-dfsan-track-origins=2``
+DataFlowSanitizer also collects intermediate loads a labeled value went 
through.
+This mode slows down program execution by a factor of 4x.
+
 Current status
 ==
 


Index: clang/docs/DataFlowSanitizer.rst
===
--- clang/docs/DataFlowSanitizer.rst
+++ clang/docs/DataFlowSanitizer.rst
@@ -191,6 +191,44 @@
 return 0;
   }
 
+Origin Tracking
+===
+
+DataFlowSanitizer can track origins of labeled values. This feature is enabled by
+``-mllvm -dfsan-track-origins=1``. For example,
+
+.. code-block:: console
+
+% cat test.cc
+#include 
+#include 
+
+int main(int argc, char** argv) {
+  int i = 0;
+  dfsan_set_label(i_label, , sizeof(i));
+  int j = i + 1;
+  dfsan_print_origin_trace(, "A flow from i to j");
+  return 0;
+}
+
+% clang++ -fsanitize=dataflow -mllvm -dfsan-track-origins=1 -fno-omit-frame-pointer -g -O2 test.cc
+% ./a.out
+Taint value 0x1 (at 0x7ffd42bf415c) origin tracking (A flow from i to j)
+Origin value: 0x1391, Taint value was stored to memory at
+  #0 0x55676db85a62 in main test.cc:7:7
+  #1 0x7f0083611bbc in __libc_start_main libc-start.c:285
+
+Origin value: 0x9e1, Taint value was created at
+  #0 0x55676db85a08 in main test.cc:6:3
+  #1 0x7f0083611bbc in __libc_start_main libc-start.c:285
+
+By ``-mllvm -dfsan-track-origins=1`` DataFlowSanitizer collects only
+intermediate stores a labeled value went through. Origin tracking slows down
+program execution by a factor of 2x on top of the usual DataFlowSanitizer
+slowdown and increases memory overhead by 1x. By ``-mllvm -dfsan-track-origins=2``
+DataFlowSanitizer also collects intermediate loads a labeled value went through.
+This mode slows down program execution by a factor of 4x.
+
 Current status
 ==
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105368: Lex: add a callback for `#pragma mark`

2021-07-02 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG24f4c3ebef63: Lex: add a callback for `#pragma mark` 
(authored by compnerd, committed by Saleem Abdulrasool 
abdul...@google.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105368/new/

https://reviews.llvm.org/D105368

Files:
  clang/include/clang/Lex/PPCallbacks.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Pragma.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp

Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -112,6 +112,20 @@
   unsigned State;
 };
 
+class PragmaMarkCallbacks : public PPCallbacks {
+public:
+  struct Mark {
+SourceLocation Location;
+std::string Trivia;
+  };
+
+  std::vector Marks;
+
+  void PragmaMark(SourceLocation Loc, StringRef Trivia) override {
+Marks.emplace_back(Mark{Loc, Trivia.str()});
+  }
+};
+
 // PPCallbacks test fixture.
 class PPCallbacksTest : public ::testing::Test {
 protected:
@@ -256,6 +270,36 @@
 return Callbacks->Results;
   }
 
+  std::vector
+  PragmaMarkCall(const char *SourceText) {
+std::unique_ptr SourceBuf =
+llvm::MemoryBuffer::getMemBuffer(SourceText, "test.c");
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(SourceBuf)));
+
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+Diags, LangOpts, Target.get());
+TrivialModuleLoader ModLoader;
+
+Preprocessor PP(std::make_shared(), Diags, LangOpts,
+SourceMgr, HeaderInfo, ModLoader, /*IILookup=*/nullptr,
+/*OwnsHeaderSearch=*/false);
+PP.Initialize(*Target);
+
+auto *Callbacks = new PragmaMarkCallbacks;
+PP.addPPCallbacks(std::unique_ptr(Callbacks));
+
+// Lex source text.
+PP.EnterMainSourceFile();
+while (true) {
+  Token Tok;
+  PP.Lex(Tok);
+  if (Tok.is(tok::eof))
+break;
+}
+
+return Callbacks->Marks;
+  }
+
   PragmaOpenCLExtensionCallbacks::CallbackParameters
   PragmaOpenCLExtensionCall(const char *SourceText) {
 LangOptions OpenCLLangOpts;
@@ -424,6 +468,24 @@
   ASSERT_EQ(ExpectedState, Parameters.State);
 }
 
+TEST_F(PPCallbacksTest, CollectMarks) {
+  const char *Source =
+"#pragma mark\n"
+"#pragma mark\r\n"
+"#pragma mark - trivia\n"
+"#pragma mark - trivia\r\n";
+
+  auto Marks = PragmaMarkCall(Source);
+
+  ASSERT_EQ(4u, Marks.size());
+  ASSERT_TRUE(Marks[0].Trivia.empty());
+  ASSERT_TRUE(Marks[1].Trivia.empty());
+  ASSERT_FALSE(Marks[2].Trivia.empty());
+  ASSERT_FALSE(Marks[3].Trivia.empty());
+  ASSERT_EQ(" - trivia", Marks[2].Trivia);
+  ASSERT_EQ(" - trivia", Marks[3].Trivia);
+}
+
 TEST_F(PPCallbacksTest, DirectiveExprRanges) {
   const auto  = DirectiveExprRange("#if FLUZZY_FLOOF\n#endif\n");
   EXPECT_EQ(Results1.size(), 1U);
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -412,9 +412,13 @@
   HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry());
 }
 
-void Preprocessor::HandlePragmaMark() {
+void Preprocessor::HandlePragmaMark(Token ) {
   assert(CurPPLexer && "No current lexer?");
-  CurLexer->ReadToEndOfLine();
+
+  SmallString<64> Buffer;
+  CurLexer->ReadToEndOfLine();
+  if (Callbacks)
+Callbacks->PragmaMark(MarkTok.getLocation(), Buffer);
 }
 
 /// HandlePragmaPoison - Handle \#pragma GCC poison.  PoisonTok is the 'poison'.
@@ -992,7 +996,7 @@
 
   void HandlePragma(Preprocessor , PragmaIntroducer Introducer,
 Token ) override {
-PP.HandlePragmaMark();
+PP.HandlePragmaMark(MarkTok);
   }
 };
 
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -2365,7 +2365,7 @@
 
 public:
   void HandlePragmaOnce(Token );
-  void HandlePragmaMark();
+  void HandlePragmaMark(Token );
   void HandlePragmaPoison();
   void HandlePragmaSystemHeader(Token );
   void HandlePragmaDependency(Token );
Index: clang/include/clang/Lex/PPCallbacks.h
===
--- clang/include/clang/Lex/PPCallbacks.h
+++ clang/include/clang/Lex/PPCallbacks.h
@@ -191,6 +191,10 @@
  StringRef Str) {
   }
 
+  /// Callback invoked when a \#pragma mark comment is read.
+  virtual void PragmaMark(SourceLocation Loc, StringRef Trivia) {
+  }
+
   /// Callback invoked when a \#pragma detect_mismatch directive is
   /// read.
   virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,
___
cfe-commits mailing list

[PATCH] D101635: [analyzer] Fix assertion in SVals.h

2021-04-30 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa27af1d8166c: [analyzer] Fix assertion in SVals.h (authored 
by vabridgers, committed by einvbri vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101635/new/

https://reviews.llvm.org/D101635

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/casts.c


Index: clang/test/Analysis/casts.c
===
--- clang/test/Analysis/casts.c
+++ clang/test/Analysis/casts.c
@@ -250,3 +250,19 @@
   if (**a == 0) // no-crash
 ;
 }
+
+// See PR50179.
+// Just don't crash.
+typedef struct taskS {
+  void *pJob;
+} taskS;
+
+typedef struct workS {
+  taskS *pTaskList;
+} workS;
+
+void *getTaskJob(unsigned jobId, workS *pWork, unsigned taskId) {
+  const taskS *pTask = pWork->pTaskList + taskId;
+  taskS task = *pTask;
+  return task.pJob;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -761,8 +761,8 @@
   // Next fixes pointer dereference using type different from its initial
   // one. See PR37503 and PR49007 for details.
   if (const auto *ER = dyn_cast(R)) {
-R = StateMgr.getStoreManager().castRegion(ER, CastTy);
-return loc::MemRegionVal(R);
+if ((R = StateMgr.getStoreManager().castRegion(ER, CastTy)))
+  return loc::MemRegionVal(R);
   }
 
   return V;


Index: clang/test/Analysis/casts.c
===
--- clang/test/Analysis/casts.c
+++ clang/test/Analysis/casts.c
@@ -250,3 +250,19 @@
   if (**a == 0) // no-crash
 ;
 }
+
+// See PR50179.
+// Just don't crash.
+typedef struct taskS {
+  void *pJob;
+} taskS;
+
+typedef struct workS {
+  taskS *pTaskList;
+} workS;
+
+void *getTaskJob(unsigned jobId, workS *pWork, unsigned taskId) {
+  const taskS *pTask = pWork->pTaskList + taskId;
+  taskS task = *pTask;
+  return task.pJob;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -761,8 +761,8 @@
   // Next fixes pointer dereference using type different from its initial
   // one. See PR37503 and PR49007 for details.
   if (const auto *ER = dyn_cast(R)) {
-R = StateMgr.getStoreManager().castRegion(ER, CastTy);
-return loc::MemRegionVal(R);
+if ((R = StateMgr.getStoreManager().castRegion(ER, CastTy)))
+  return loc::MemRegionVal(R);
   }
 
   return V;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98918: [clang][lit] Allow test cases to use the compiler that are used to compile Clang

2021-03-24 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d8fc086ae26: [clang][lit] Allow test cases to use the 
compiler that are used to compile Clang (authored by OikawaKirie, committed by 
Balazs Benics balazsben...@sigmatechnology.se).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98918/new/

https://reviews.llvm.org/D98918

Files:
  clang/test/lit.cfg.py
  clang/test/lit.site.cfg.py.in


Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -15,6 +15,7 @@
 config.clang_tools_dir = path(r"@CLANG_TOOLS_DIR@")
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.target_triple = "@TARGET_TRIPLE@"
+config.host_cc = "@CMAKE_C_COMPILER@"
 config.host_cxx = "@CMAKE_CXX_COMPILER@"
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -92,6 +92,9 @@
 ('%hmaptool', "'%s' %s" % (config.python_executable,
  os.path.join(config.clang_tools_dir, 
'hmaptool'
 
+config.substitutions.append(('%host_cc', config.host_cc))
+config.substitutions.append(('%host_cxx', config.host_cxx))
+
 
 # Plugins (loadable modules)
 if config.has_plugins and config.llvm_plugin_ext:


Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -15,6 +15,7 @@
 config.clang_tools_dir = path(r"@CLANG_TOOLS_DIR@")
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.target_triple = "@TARGET_TRIPLE@"
+config.host_cc = "@CMAKE_C_COMPILER@"
 config.host_cxx = "@CMAKE_CXX_COMPILER@"
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -92,6 +92,9 @@
 ('%hmaptool', "'%s' %s" % (config.python_executable,
  os.path.join(config.clang_tools_dir, 'hmaptool'
 
+config.substitutions.append(('%host_cc', config.host_cc))
+config.substitutions.append(('%host_cxx', config.host_cxx))
+
 
 # Plugins (loadable modules)
 if config.has_plugins and config.llvm_plugin_ext:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99576: [ASTImporter][NFC] Improve test coverage

2021-03-31 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG936d1e97a32d: [ASTImporter][NFC] Improve test coverage 
(authored by Balazs Benics balazsben...@sigmatechnology.se).

Changed prior to commit:
  https://reviews.llvm.org/D99576?vs=334101=334392#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99576/new/

https://reviews.llvm.org/D99576

Files:
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3064,6 +3064,72 @@
   EXPECT_EQ(ToF1, ToF2);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportBitfields) {
+  Decl *FromTU = getTuDecl("struct A { unsigned x : 3; };", Lang_CXX03);
+  auto *FromF =
+  FirstDeclMatcher().match(FromTU, fieldDecl(hasName("x")));
+
+  ASSERT_TRUE(FromF->isBitField());
+  ASSERT_EQ(3u, FromF->getBitWidthValue(FromTU->getASTContext()));
+  auto *ToField = Import(FromF, Lang_CXX03);
+  auto *ToTU = ToField->getTranslationUnitDecl();
+
+  EXPECT_TRUE(ToField->isBitField());
+  EXPECT_EQ(3u, ToField->getBitWidthValue(ToTU->getASTContext()));
+
+  const auto *FromBT = FromF->getBitWidth()->getType()->getAs();
+  const auto *ToBT = ToField->getBitWidth()->getType()->getAs();
+  ASSERT_TRUE(FromBT);
+  ASSERT_EQ(BuiltinType::Int, FromBT->getKind());
+  EXPECT_TRUE(ToBT);
+  EXPECT_EQ(BuiltinType::Int, ToBT->getKind());
+}
+
+struct ImportBlock : ASTImporterOptionSpecificTestBase {};
+const internal::VariadicDynCastAllOfMatcher blockDecl;
+TEST_P(ImportBlock, ImportBlocksAreUnsupported) {
+  const auto *Code = R"(
+void test_block__capture_null() {
+  int *p = 0;
+  ^(){
+*p = 1;
+  }();
+})";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX03);
+  auto *FromBlock = FirstDeclMatcher().match(FromTU, blockDecl());
+  ASSERT_TRUE(FromBlock);
+
+  auto ToBlockOrError = importOrError(FromBlock, Lang_CXX03);
+
+  const auto ExpectUnsupportedConstructError = [](const ImportError ) {
+EXPECT_EQ(ImportError::UnsupportedConstruct, Error.Error);
+  };
+  llvm::handleAllErrors(ToBlockOrError.takeError(),
+ExpectUnsupportedConstructError);
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportParmVarDecl) {
+  const auto *Code = R"(
+template  struct Wrapper {
+  Wrapper(T Value = {}) {}
+};
+template class Wrapper;
+)";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromVar = FirstDeclMatcher().match(
+  FromTU, parmVarDecl(hasType(asString("int";
+  ASSERT_TRUE(FromVar);
+  ASSERT_TRUE(FromVar->hasUninstantiatedDefaultArg());
+  ASSERT_TRUE(FromVar->getUninstantiatedDefaultArg());
+
+  const auto *ToVar = Import(FromVar, Lang_CXX11);
+  EXPECT_TRUE(ToVar);
+  EXPECT_TRUE(ToVar->hasUninstantiatedDefaultArg());
+  EXPECT_TRUE(ToVar->getUninstantiatedDefaultArg());
+  EXPECT_NE(FromVar->getUninstantiatedDefaultArg(),
+ToVar->getUninstantiatedDefaultArg());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportOfNonEquivalentField) {
   Decl *ToF1;
   {
@@ -6272,6 +6338,11 @@
   std::vector{
   "-ffixed-point"}), );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportBlock,
+ExtendWithOptions(DefaultTestArrayForRunOptions,
+  std::vector{
+  "-fblocks"}), );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
 DefaultTestValuesForRunOptions, );
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3064,6 +3064,72 @@
   EXPECT_EQ(ToF1, ToF2);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportBitfields) {
+  Decl *FromTU = getTuDecl("struct A { unsigned x : 3; };", Lang_CXX03);
+  auto *FromF =
+  FirstDeclMatcher().match(FromTU, fieldDecl(hasName("x")));
+
+  ASSERT_TRUE(FromF->isBitField());
+  ASSERT_EQ(3u, FromF->getBitWidthValue(FromTU->getASTContext()));
+  auto *ToField = Import(FromF, Lang_CXX03);
+  auto *ToTU = ToField->getTranslationUnitDecl();
+
+  EXPECT_TRUE(ToField->isBitField());
+  EXPECT_EQ(3u, ToField->getBitWidthValue(ToTU->getASTContext()));
+
+  const auto *FromBT = FromF->getBitWidth()->getType()->getAs();
+  const auto *ToBT = ToField->getBitWidth()->getType()->getAs();
+  ASSERT_TRUE(FromBT);
+  ASSERT_EQ(BuiltinType::Int, FromBT->getKind());
+  EXPECT_TRUE(ToBT);
+  EXPECT_EQ(BuiltinType::Int, ToBT->getKind());
+}
+
+struct ImportBlock : ASTImporterOptionSpecificTestBase {};
+const internal::VariadicDynCastAllOfMatcher blockDecl;
+TEST_P(ImportBlock, 

[PATCH] D86870: [analyzer] Add more tests for ArrayBoundCheckerV2

2021-03-10 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0dc0e2a9ab3c: [analyzer][NFC] Add more tests for 
ArrayBoundCheckerV2 (authored by Balazs Benics 
balazsben...@sigmatechnology.se).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86870/new/

https://reviews.llvm.org/D86870

Files:
  clang/test/Analysis/out-of-bounds-false-positive.c

Index: clang/test/Analysis/out-of-bounds-false-positive.c
===
--- /dev/null
+++ clang/test/Analysis/out-of-bounds-false-positive.c
@@ -0,0 +1,101 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.ArrayBoundV2,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false -verify %s
+
+void clang_analyzer_eval(int);
+void clang_analyzer_printState();
+
+typedef unsigned long long size_t;
+const char a[] = "abcd"; // extent: 5 bytes
+
+void symbolic_size_t_and_int0(size_t len) {
+  // FIXME: Should not warn for this.
+  (void)a[len + 1]; // expected-warning {{Out of bound memory access}}
+  // We infered that the 'len' must be in a specific range to make the previous indexing valid.
+  // len: [0,3]
+  clang_analyzer_eval(len <= 3); // expected - warning {{TRUE}}
+  clang_analyzer_eval(len <= 2); // expected - warning {{UNKNOWN}}
+}
+
+void symbolic_size_t_and_int1(size_t len) {
+  (void)a[len]; // no-warning
+  // len: [0,4]
+  clang_analyzer_eval(len <= 4); // expected-warning {{TRUE}}
+  clang_analyzer_eval(len <= 3); // expected-warning {{UNKNOWN}}
+}
+
+void symbolic_size_t_and_int2(size_t len) {
+  (void)a[len - 1]; // no-warning
+  // len: [1,5]
+  clang_analyzer_eval(1 <= len && len <= 5); // expected-warning {{TRUE}}
+  clang_analyzer_eval(2 <= len); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 4); // expected-warning {{UNKNOWN}}
+}
+
+void symbolic_uint_and_int0(unsigned len) {
+  (void)a[len + 1]; // no-warning
+  // len: [0,3]
+  clang_analyzer_eval(0 <= len && len <= 3); // expected-warning {{TRUE}}
+  clang_analyzer_eval(1 <= len); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 2); // expected-warning {{UNKNOWN}}
+}
+
+void symbolic_uint_and_int1(unsigned len) {
+  (void)a[len]; // no-warning
+  // len: [0,4]
+  clang_analyzer_eval(0 <= len && len <= 4); // expected-warning {{TRUE}}
+  clang_analyzer_eval(1 <= len); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 3); // expected-warning {{UNKNOWN}}
+}
+void symbolic_uint_and_int2(unsigned len) {
+  (void)a[len - 1]; // no-warning
+  // len: [1,5]
+  clang_analyzer_eval(1 <= len && len <= 5); // expected-warning {{TRUE}}
+  clang_analyzer_eval(2 <= len); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 4); // expected-warning {{UNKNOWN}}
+}
+
+void symbolic_int_and_int0(int len) {
+  (void)a[len + 1]; // no-warning
+  // len: [-1,3]
+  clang_analyzer_eval(-1 <= len && len <= 3); // expected-warning {{TRUE}}
+  clang_analyzer_eval(0 <= len);  // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 2);  // expected-warning {{UNKNOWN}}
+}
+void symbolic_int_and_int1(int len) {
+  (void)a[len]; // no-warning
+  // len: [0,4]
+  clang_analyzer_eval(0 <= len && len <= 4); // expected-warning {{TRUE}}
+  clang_analyzer_eval(1 <= len); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 3); // expected-warning {{UNKNOWN}}
+}
+void symbolic_int_and_int2(int len) {
+  (void)a[len - 1]; // no-warning
+  // len: [1,5]
+  clang_analyzer_eval(1 <= len && len <= 5); // expected-warning {{TRUE}}
+  clang_analyzer_eval(2 <= len); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 4); // expected-warning {{UNKNOWN}}
+}
+
+void symbolic_longlong_and_int0(long long len) {
+  (void)a[len + 1]; // no-warning
+  // len: [-1,3]
+  clang_analyzer_eval(-1 <= len && len <= 3); // expected-warning {{TRUE}}
+  clang_analyzer_eval(0 <= len);  // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 2);  // expected-warning {{UNKNOWN}}
+}
+
+void symbolic_longlong_and_int1(long long len) {
+  (void)a[len]; // no-warning
+  // len: [0,4]
+  clang_analyzer_eval(0 <= len && len <= 4); // expected-warning {{TRUE}}
+  clang_analyzer_eval(1 <= len); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 3); // expected-warning {{UNKNOWN}}
+}
+
+void symbolic_longlong_and_int2(long long len) {
+  (void)a[len - 1]; // no-warning
+  // len: [1,5]
+  clang_analyzer_eval(1 <= len && len <= 5); // expected-warning {{TRUE}}
+  clang_analyzer_eval(2 <= len); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 4); // expected-warning {{UNKNOWN}}
+}
___
cfe-commits mailing list

[PATCH] D96586: [analyzer][CTU][NFC] Add an extra regression test

2021-03-10 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e0ea9ffb802: [analyzer][CTU][NFC] Add an extra regression 
test (authored by Balazs Benics balazsben...@sigmatechnology.se).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96586/new/

https://reviews.llvm.org/D96586

Files:
  clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
  clang/test/Analysis/ctu-inherited-default-ctor.cpp


Index: clang/test/Analysis/ctu-inherited-default-ctor.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-inherited-default-ctor.cpp
@@ -0,0 +1,28 @@
+// Should not crash with '-analyzer-opt-analyze-headers' option during CTU 
analysis.
+//
+// RUN: rm -r %t && mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-inherited-default-ctor-other.cpp.ast \
+// RUN:%S/Inputs/ctu-inherited-default-ctor-other.cpp
+// RUN: echo "c:@N@clang@S@DeclContextLookupResult@SingleElementDummyList 
ctu-inherited-default-ctor-other.cpp.ast" \
+// RUN:   > %t/ctudir/externalDefMap.txt
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-opt-analyze-headers \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -analyzer-config display-ctu-progress=true \
+// RUN:   -verify %s 2>&1 | FileCheck %s
+//
+// expected-no-diagnostics
+//
+// CHECK: CTU loaded AST file: ctu-inherited-default-ctor-other.cpp.ast
+
+namespace clang {}
+namespace llvm {}
+namespace clang {
+class DeclContextLookupResult {
+  static int *const SingleElementDummyList;
+};
+} // namespace clang
Index: clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
@@ -0,0 +1,27 @@
+namespace llvm {
+template 
+class impl;
+// basecase
+template 
+class impl {};
+// recursion
+template 
+class impl : impl {
+  using child = impl;
+  using child::child; // no-crash
+  impl(T);
+};
+template 
+class container : impl<0, TS...> {};
+} // namespace llvm
+namespace clang {
+class fun {
+  llvm::container k;
+  fun() {}
+};
+class DeclContextLookupResult {
+  static int *const SingleElementDummyList;
+};
+} // namespace clang
+using namespace clang;
+int *const DeclContextLookupResult::SingleElementDummyList = nullptr;


Index: clang/test/Analysis/ctu-inherited-default-ctor.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-inherited-default-ctor.cpp
@@ -0,0 +1,28 @@
+// Should not crash with '-analyzer-opt-analyze-headers' option during CTU analysis.
+//
+// RUN: rm -r %t && mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-inherited-default-ctor-other.cpp.ast \
+// RUN:%S/Inputs/ctu-inherited-default-ctor-other.cpp
+// RUN: echo "c:@N@clang@S@DeclContextLookupResult@SingleElementDummyList ctu-inherited-default-ctor-other.cpp.ast" \
+// RUN:   > %t/ctudir/externalDefMap.txt
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-opt-analyze-headers \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -analyzer-config display-ctu-progress=true \
+// RUN:   -verify %s 2>&1 | FileCheck %s
+//
+// expected-no-diagnostics
+//
+// CHECK: CTU loaded AST file: ctu-inherited-default-ctor-other.cpp.ast
+
+namespace clang {}
+namespace llvm {}
+namespace clang {
+class DeclContextLookupResult {
+  static int *const SingleElementDummyList;
+};
+} // namespace clang
Index: clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
@@ -0,0 +1,27 @@
+namespace llvm {
+template 
+class impl;
+// basecase
+template 
+class impl {};
+// recursion
+template 
+class impl : impl {
+  using child = impl;
+  using child::child; // no-crash
+  impl(T);
+};
+template 
+class container : impl<0, TS...> {};
+} // namespace llvm
+namespace clang {
+class fun {
+  llvm::container k;
+  fun() {}
+};
+class DeclContextLookupResult {
+  static int *const SingleElementDummyList;
+};
+} // namespace clang
+using namespace clang;
+int *const DeclContextLookupResult::SingleElementDummyList = nullptr;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85424: [Analyzer] Crash fix for alpha.cplusplus.IteratorRange

2021-03-10 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbcc662484a95: [analyzer] Crash fix for 
alpha.cplusplus.IteratorRange (authored by baloghadamsoftware, committed by 
Balazs Benics balazsben...@sigmatechnology.se).

Changed prior to commit:
  https://reviews.llvm.org/D85424?vs=290967=329600#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85424/new/

https://reviews.llvm.org/D85424

Files:
  clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
  clang/test/Analysis/iterator-range.cpp


Index: clang/test/Analysis/iterator-range.cpp
===
--- clang/test/Analysis/iterator-range.cpp
+++ clang/test/Analysis/iterator-range.cpp
@@ -939,3 +939,10 @@
   auto i0 = c.begin(), i1 = c.end();
   ptrdiff_t len = i1 - i0; // no-crash
 }
+
+int uninit_var(int n) {
+  int uninit; // expected-note{{'uninit' declared without an initial value}}
+  return n - uninit; // no-crash
+  // expected-warning@-1 {{The right operand of '-' is a garbage value}}
+  // expected-note@-2 {{The right operand of '-' is a garbage value}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
@@ -228,7 +228,7 @@
 Value = State->getRawSVal(*ValAsLoc);
   }
 
-  if (Value.isUnknown())
+  if (Value.isUnknownOrUndef())
 return;
 
   // Incremention or decremention by 0 is never a bug.


Index: clang/test/Analysis/iterator-range.cpp
===
--- clang/test/Analysis/iterator-range.cpp
+++ clang/test/Analysis/iterator-range.cpp
@@ -939,3 +939,10 @@
   auto i0 = c.begin(), i1 = c.end();
   ptrdiff_t len = i1 - i0; // no-crash
 }
+
+int uninit_var(int n) {
+  int uninit; // expected-note{{'uninit' declared without an initial value}}
+  return n - uninit; // no-crash
+  // expected-warning@-1 {{The right operand of '-' is a garbage value}}
+  // expected-note@-2 {{The right operand of '-' is a garbage value}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
@@ -228,7 +228,7 @@
 Value = State->getRawSVal(*ValAsLoc);
   }
 
-  if (Value.isUnknown())
+  if (Value.isUnknownOrUndef())
 return;
 
   // Incremention or decremention by 0 is never a bug.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97936: [analyzer][docs][NFC] Fix typo in checkers.rst

2021-03-10 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG57e149d38628: [analyzer][docs][NFC] Fix typo in checkers.rst 
(authored by Balazs Benics balazsben...@sigmatechnology.se).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97936/new/

https://reviews.llvm.org/D97936

Files:
  clang/docs/analyzer/checkers.rst


Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -1476,6 +1476,9 @@
return y;
  }
 
+alpha.core
+^^
+
 .. _alpha-core-BoolAssignment:
 
 alpha.core.BoolAssignment (ObjC)
@@ -1488,9 +1491,6 @@
BOOL b = -1; // warn
  }
 
-alpha.core
-^^
-
 .. _alpha-core-C11Lock:
 
 alpha.core.C11Lock


Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -1476,6 +1476,9 @@
return y;
  }
 
+alpha.core
+^^
+
 .. _alpha-core-BoolAssignment:
 
 alpha.core.BoolAssignment (ObjC)
@@ -1488,9 +1491,6 @@
BOOL b = -1; // warn
  }
 
-alpha.core
-^^
-
 .. _alpha-core-C11Lock:
 
 alpha.core.C11Lock
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98552: [NFC] Adjust SmallVector.h header to workaround XL build compiler issue

2021-03-12 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0bf2da53c12b: [NFC] Adjust SmallVector.h header to 
workaround XL build compiler issue (authored by xling-Liao 
xiangling.l...@ibm.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98552/new/

https://reviews.llvm.org/D98552

Files:
  clang/include/clang/Basic/LLVM.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -663,7 +663,7 @@
   // Generate arguments from the dummy invocation. If Generate is the
   // inverse of Parse, the newly generated arguments must have the same
   // semantics as the original.
-  SmallVector GeneratedArgs1;
+  SmallVector GeneratedArgs1;
   Generate(DummyInvocation, GeneratedArgs1, SA);
 
   // Run the second parse, now on the generated arguments, and with the real
@@ -683,7 +683,7 @@
 
   // Generate arguments again, this time from the options we will end up using
   // for the rest of the compilation.
-  SmallVector GeneratedArgs2;
+  SmallVector GeneratedArgs2;
   Generate(RealInvocation, GeneratedArgs2, SA);
 
   // Compares two lists of generated arguments.
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1913,7 +1913,7 @@
 emitCapturedStmtCall(CodeGenFunction , EmittedClosureTy Cap,
  llvm::ArrayRef Args) {
   // Append the closure context to the argument.
-  llvm::SmallVector EffectiveArgs;
+  SmallVector EffectiveArgs;
   EffectiveArgs.reserve(Args.size() + 1);
   llvm::append_range(EffectiveArgs, Args);
   EffectiveArgs.push_back(Cap.second);
Index: clang/include/clang/Basic/LLVM.h
===
--- clang/include/clang/Basic/LLVM.h
+++ clang/include/clang/Basic/LLVM.h
@@ -22,6 +22,9 @@
 // None.h includes an enumerator that is desired & cannot be forward declared
 // without a definition of NoneType.
 #include "llvm/ADT/None.h"
+// Add this header as a workaround to prevent `too few template arguments for
+// class template 'SmallVector'` building error with build compilers like XL.
+#include "llvm/ADT/SmallVector.h"
 
 namespace llvm {
   // ADT's.


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -663,7 +663,7 @@
   // Generate arguments from the dummy invocation. If Generate is the
   // inverse of Parse, the newly generated arguments must have the same
   // semantics as the original.
-  SmallVector GeneratedArgs1;
+  SmallVector GeneratedArgs1;
   Generate(DummyInvocation, GeneratedArgs1, SA);
 
   // Run the second parse, now on the generated arguments, and with the real
@@ -683,7 +683,7 @@
 
   // Generate arguments again, this time from the options we will end up using
   // for the rest of the compilation.
-  SmallVector GeneratedArgs2;
+  SmallVector GeneratedArgs2;
   Generate(RealInvocation, GeneratedArgs2, SA);
 
   // Compares two lists of generated arguments.
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1913,7 +1913,7 @@
 emitCapturedStmtCall(CodeGenFunction , EmittedClosureTy Cap,
  llvm::ArrayRef Args) {
   // Append the closure context to the argument.
-  llvm::SmallVector EffectiveArgs;
+  SmallVector EffectiveArgs;
   EffectiveArgs.reserve(Args.size() + 1);
   llvm::append_range(EffectiveArgs, Args);
   EffectiveArgs.push_back(Cap.second);
Index: clang/include/clang/Basic/LLVM.h
===
--- clang/include/clang/Basic/LLVM.h
+++ clang/include/clang/Basic/LLVM.h
@@ -22,6 +22,9 @@
 // None.h includes an enumerator that is desired & cannot be forward declared
 // without a definition of NoneType.
 #include "llvm/ADT/None.h"
+// Add this header as a workaround to prevent `too few template arguments for
+// class template 'SmallVector'` building error with build compilers like XL.
+#include "llvm/ADT/SmallVector.h"
 
 namespace llvm {
   // ADT's.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98707: [clang][ASTImporter] Fix import of VarDecl regarding thread local storage spec

2021-03-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc1fb23c1aadd: [clang][ASTImporter] Fix import of VarDecl 
regarding thread local storage spec (authored by Balazs Benics 
balazsben...@sigmatechnology.se).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98707/new/

https://reviews.llvm.org/D98707

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -735,6 +735,12 @@
  has(declStmt(hasSingleDecl(varDecl(hasName("d");
 }
 
+TEST_P(ImportDecl, ImportedVarDeclPreservesThreadLocalStorage) {
+  MatchVerifier Verifier;
+  testImport("thread_local int declToImport;", Lang_CXX11, "", Lang_CXX11,
+ Verifier, varDecl(hasThreadStorageDuration()));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportRecordTypeInFunc) {
   Decl *FromTU = getTuDecl("int declToImport() { "
"  struct data_t {int a;int b;};"
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -4018,6 +4018,7 @@
   D->getStorageClass()))
 return ToVar;
 
+  ToVar->setTSCSpec(D->getTSCSpec());
   ToVar->setQualifierInfo(ToQualifierLoc);
   ToVar->setAccess(D->getAccess());
   ToVar->setLexicalDeclContext(LexicalDC);


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -735,6 +735,12 @@
  has(declStmt(hasSingleDecl(varDecl(hasName("d");
 }
 
+TEST_P(ImportDecl, ImportedVarDeclPreservesThreadLocalStorage) {
+  MatchVerifier Verifier;
+  testImport("thread_local int declToImport;", Lang_CXX11, "", Lang_CXX11,
+ Verifier, varDecl(hasThreadStorageDuration()));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportRecordTypeInFunc) {
   Decl *FromTU = getTuDecl("int declToImport() { "
"  struct data_t {int a;int b;};"
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -4018,6 +4018,7 @@
   D->getStorageClass()))
 return ToVar;
 
+  ToVar->setTSCSpec(D->getTSCSpec());
   ToVar->setQualifierInfo(ToQualifierLoc);
   ToVar->setAccess(D->getAccess());
   ToVar->setLexicalDeclContext(LexicalDC);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97759: [doc] Fix description of _Float16

2021-03-03 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb46a1b129f68: [doc] Fix description of _Float16 (authored by 
Kito Cheng kito.ch...@sifive.com).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D97759?vs=327387=328023#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97759/new/

https://reviews.llvm.org/D97759

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -542,7 +542,7 @@
 Clang uses the ``binary16`` format from IEEE 754-2008 for ``__fp16``, not the 
ARM
 alternative format.
 
-``_Float16`` is an extended floating-point type.  This means that, just like 
arithmetic on
+``_Float16`` is an interchange floating-point type.  This means that, just 
like arithmetic on
 ``float`` or ``double``, arithmetic on ``_Float16`` operands is formally 
performed in the
 ``_Float16`` type, so that e.g. the result of adding two ``_Float16`` values 
has type
 ``_Float16``.  The behavior of ``_Float16`` is specified by ISO/IEC TS 
18661-3:2015


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -542,7 +542,7 @@
 Clang uses the ``binary16`` format from IEEE 754-2008 for ``__fp16``, not the ARM
 alternative format.
 
-``_Float16`` is an extended floating-point type.  This means that, just like arithmetic on
+``_Float16`` is an interchange floating-point type.  This means that, just like arithmetic on
 ``float`` or ``double``, arithmetic on ``_Float16`` operands is formally performed in the
 ``_Float16`` type, so that e.g. the result of adding two ``_Float16`` values has type
 ``_Float16``.  The behavior of ``_Float16`` is specified by ISO/IEC TS 18661-3:2015
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97533: [Clang][Coroutine][DebugInfo] remove useless debug info for coroutine parameters

2021-04-11 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a6a80b641bc: [Clang][Coroutine][DebugInfo] In c++ 
coroutine, clang will emit different debug… (authored by yifeng.dongyifeng 
yifeng.dongyif...@alibaba-inc.com).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97533/new/

https://reviews.llvm.org/D97533

Files:
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGenCoroutines/coro-dwarf.cpp

Index: clang/test/CodeGenCoroutines/coro-dwarf.cpp
===
--- /dev/null
+++ clang/test/CodeGenCoroutines/coro-dwarf.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -std=c++2a -fcoroutines-ts -triple=x86_64 -dwarf-version=4 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
+
+namespace std::experimental {
+template  struct coroutine_traits;
+
+template  struct coroutine_handle {
+  coroutine_handle() = default;
+  static coroutine_handle from_address(void *) noexcept;
+};
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+  coroutine_handle() = default;
+  template 
+  coroutine_handle(coroutine_handle) noexcept;
+};
+} // namespace std::experimental
+
+struct suspend_always {
+  bool await_ready() noexcept;
+  void await_suspend(std::experimental::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+template  struct std::experimental::coroutine_traits {
+  struct promise_type {
+void get_return_object() noexcept;
+suspend_always initial_suspend() noexcept;
+suspend_always final_suspend() noexcept;
+void return_void() noexcept;
+promise_type();
+~promise_type() noexcept;
+void unhandled_exception() noexcept;
+  };
+};
+
+// TODO: Not supported yet
+struct CopyOnly {
+  int val;
+  CopyOnly(const CopyOnly &) noexcept;
+  CopyOnly(CopyOnly &&) = delete;
+  ~CopyOnly();
+};
+
+struct MoveOnly {
+  int val;
+  MoveOnly(const MoveOnly &) = delete;
+  MoveOnly(MoveOnly &&) noexcept;
+  ~MoveOnly();
+};
+
+struct MoveAndCopy {
+  int val;
+  MoveAndCopy(const MoveAndCopy &) noexcept;
+  MoveAndCopy(MoveAndCopy &&) noexcept;
+  ~MoveAndCopy();
+};
+
+void consume(int, int, int) noexcept;
+
+void f_coro(int val, MoveOnly moParam, MoveAndCopy mcParam) {
+  consume(val, moParam.val, mcParam.val);
+  co_return;
+}
+
+// CHECK: ![[SP:[0-9]+]] = distinct !DISubprogram(name: "f_coro", linkageName: "_Z6f_coroi8MoveOnly11MoveAndCopy"
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "val", arg: 1, scope: ![[SP]], file: !8, line: 60, type: !{{[0-9]+}})
+// CHECK: !{{[0-9]+}} = !DILocation(line: 60, column: 17, scope: ![[SP]])
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "moParam", arg: 2, scope: ![[SP]], file: !8, line: 60, type: !{{[0-9]+}})
+// CHECK: !{{[0-9]+}} = !DILocation(line: 60, column: 31, scope: ![[SP]])
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "mcParam", arg: 3, scope: ![[SP]], file: !8, line: 60, type: !{{[0-9]+}})
+// CHECK: !{{[0-9]+}} = !DILocation(line: 60, column: 52, scope: ![[SP]])
+// CHECK: !{{[0-9]+}} = !DILocation(line: 60, column: 61, scope: ![[SP]])
+// CHECK: !{{[0-9]+}} = !DILocation(line: 60, column: 6, scope: ![[SP]])
+// CHECK: !{{[0-9]+}} = !DILocation(line: 0, scope: ![[SP]])
+// CHECK-NOT: !{{[0-9]+}} = !DILocalVariable(name: "val", scope: ![[SP]], type: !{{[0-9]+}}, flags: DIFlagArtificial)
+// CHECK-NOT: !{{[0-9]+}} = !DILocalVariable(name: "moParam", scope: ![[SP]], type: !{{[0-9]+}}, flags: DIFlagArtificial)
+// CHECK-NOT:: !{{[0-9]+}} = !DILocalVariable(name: "mcParam", scope: ![[SP]], type: !{{[0-9]+}}, flags: DIFlagArtificial)
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -325,6 +325,9 @@
   QualType FnRetTy;
   llvm::Function *CurFn = nullptr;
 
+  /// Save Parameter Decl for coroutine.
+  llvm::SmallVector FnArgs;
+
   // Holds coroutine data if the current function is a coroutine. We use a
   // wrapper to manage its lifetime, so that we don't have to define CGCoroData
   // in this header.
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1331,6 +1331,11 @@
   // Emit the standard function prologue.
   StartFunction(GD, ResTy, Fn, FnInfo, Args, Loc, BodyRange.getBegin());
 
+  // Save parameters for coroutine function.
+  if (Body && isa_and_nonnull(Body))
+for (const auto *ParamDecl : FD->parameters())
+  FnArgs.push_back(ParamDecl);
+
   

[PATCH] D93203: [PS4] handle dllimport/export w.r.t vtables/rtti

2021-04-13 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeae2d4b8520c: [Windows Itanium][PS4] handle dllimport/export 
w.r.t vtables/rtti (authored by Ben Dunbobbin ben.dunbob...@sony.com).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D93203?vs=318527=337091#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93203/new/

https://reviews.llvm.org/D93203

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp

Index: clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp
@@ -0,0 +1,210 @@
+// For a class that has a vtable (and hence, also has a typeinfo symbol for
+// RTTI), if a user marks either:
+//
+//  (a) the entire class as dllexport (dllimport), or
+//  (b) all non-inline virtual methods of the class as dllexport (dllimport)
+//
+// then Clang must export the vtable and typeinfo symbol from the TU where they
+// are defined (the TU containing the definition of the Itanium C++ ABI "key
+// function"), and must import them in other modules where they are referenced.
+//
+// Conversely to point (b), if some (but not all) of the non-inline virtual
+// methods of a class are marked as dllexport (dllimport), then the vtable and
+// typeinfo symbols must not be exported (imported).  This will result in a
+// link-time failure when linking the importing module.  This link-time failure
+// is the desired behavior, because the Microsoft toolchain also gets a
+// link-time failure in these cases (and since __declspec(dllexport)
+// (__declspec(dllimport)) is a Microsoft extension, our intention is to mimic
+// that Microsoft behavior).
+//
+// Side note: It is within the bodies of constructors (and in some cases,
+// destructors) that the vtable is explicitly referenced.  In case (a) above,
+// where the entire class is exported (imported), then all constructors (among
+// other things) are exported (imported).  So for that situation, an importing
+// module for a well-formed program will not actually reference the vtable,
+// since constructor calls will all be to functions external to that module
+// (and imported into it, from the exporting module).  I.e., all vtable
+// references will be in that module where the constructor and destructor
+// bodies are, therefore, there will not be a need to import the vtable in
+// that case.
+//
+// This test contains 6 test classes:
+//   2 for point (a),
+//   2 for point (b),
+//   and 2 negative tests for the converse of point (b).
+//
+// The two tests for each of these points are one for importing, and one for
+// exporting.
+
+// RUN: %clang_cc1 -I%S -fdeclspec -triple x86_64-unknown-windows-itanium -emit-llvm -o - %s -fhalf-no-semantic-interposition | FileCheck %s -check-prefix=WI
+// RUN: %clang_cc1 -I%S -fdeclspec -triple x86_64-scei-windows-itanium -emit-llvm -o - %s -fhalf-no-semantic-interposition | FileCheck %s --check-prefixes=PS4,SCEI_WI
+// RUN: %clang_cc1 -I%S -fdeclspec -triple x86_64-scei-ps4 -emit-llvm -o - %s -fhalf-no-semantic-interposition | FileCheck %s --check-prefixes=PS4,SCEI_PS4
+
+#include 
+
+// Case (a) -- Import Aspect
+// The entire class is imported.  The typeinfo symbol must also be imported,
+// but the vtable will not be referenced, and so does not need to be imported
+// (as described in the "Side note", above).
+//
+// PS4-DAG: @_ZTI10FullImport = {{.*}}dllimport
+// WI-DAG: @_ZTI10FullImport = external dllimport constant i8*
+struct __declspec(dllimport) FullImport
+{
+  virtual void getId() {}
+  virtual void Bump();
+  virtual void Decrement();
+};
+
+// 'FullImport::Bump()' is the key function, so the vtable and typeinfo symbol
+// of 'FullImport' will be defined in the TU that contains the definition of
+// 'Bump()' (and they must be exported from there).
+void FullImportTest()
+{
+  typeid(FullImport).name();
+}
+
+///
+
+// Case (a) -- Export Aspect
+// The entire class is exported.  The vtable and typeinfo symbols must also be
+// exported,
+//
+// PS4-DAG: @_ZTV10FullExport ={{.*}}dllexport
+// WI-DAG: @_ZTV10FullExport ={{.*}}dllexport
+// PS4-DAG: @_ZTI10FullExport ={{.*}}dllexport
+// WI-DAG: @_ZTI10FullExport = dso_local dllexport constant {
+struct __declspec(dllexport) FullExport // Easy case: Entire class is exported.
+{
+  virtual void getId() {}
+  virtual void Bump();
+  virtual void Decrement();
+};
+
+// This is the key function of the class 'FullExport', so the vtable and
+// typeinfo symbols of 'FullExport' will be defined in this TU, and so they
+// must be exported from this TU.
+void FullExport::Bump()
+{
+  

[PATCH] D99959: [analyzer][NFC] Add tests for extents

2021-04-07 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf0e102c1a39f: [analyzer][NFC] Add tests for extents 
(authored by Balazs Benics balazsben...@sigmatechnology.se).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99959/new/

https://reviews.llvm.org/D99959

Files:
  clang/test/Analysis/malloc.c


Index: clang/test/Analysis/malloc.c
===
--- clang/test/Analysis/malloc.c
+++ clang/test/Analysis/malloc.c
@@ -8,6 +8,8 @@
 #include "Inputs/system-header-simulator.h"
 
 void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
+void clang_analyzer_dumpExtent(void *);
 
 // Without -fms-compatibility, wchar_t isn't a builtin type. MSVC defines
 // _WCHAR_T_DEFINED if wchar_t is available. Microsoft recommends that you use
@@ -1883,3 +1885,14 @@
   s->memP = malloc(sizeof(int));
   free(s);
 } // FIXME: should warn here
+
+int conjure();
+void testExtent() {
+  int x = conjure();
+  clang_analyzer_dump(x);
+  // expected-warning-re@-1 ^conj_\$[[:digit:]]+{int, LC1, S[[:digit:]]+, 
#1}}
+  int *p = (int *)malloc(x);
+  clang_analyzer_dumpExtent(p);
+  // expected-warning-re@-1 ^conj_\$[[:digit:]]+{int, LC1, S[[:digit:]]+, 
#1}}
+  free(p);
+}


Index: clang/test/Analysis/malloc.c
===
--- clang/test/Analysis/malloc.c
+++ clang/test/Analysis/malloc.c
@@ -8,6 +8,8 @@
 #include "Inputs/system-header-simulator.h"
 
 void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
+void clang_analyzer_dumpExtent(void *);
 
 // Without -fms-compatibility, wchar_t isn't a builtin type. MSVC defines
 // _WCHAR_T_DEFINED if wchar_t is available. Microsoft recommends that you use
@@ -1883,3 +1885,14 @@
   s->memP = malloc(sizeof(int));
   free(s);
 } // FIXME: should warn here
+
+int conjure();
+void testExtent() {
+  int x = conjure();
+  clang_analyzer_dump(x);
+  // expected-warning-re@-1 ^conj_\$[[:digit:]]+{int, LC1, S[[:digit:]]+, #1}}
+  int *p = (int *)malloc(x);
+  clang_analyzer_dumpExtent(p);
+  // expected-warning-re@-1 ^conj_\$[[:digit:]]+{int, LC1, S[[:digit:]]+, #1}}
+  free(p);
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93222: [analyzer] Introduce MacroExpansionContext to libAnalysis

2021-02-22 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6e3071007b4c: [analyzer] Introduce MacroExpansionContext to 
libAnalysis (authored by steakhal, committed by Balazs Benics 
balazsben...@sigmatechnology.se).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93222/new/

https://reviews.llvm.org/D93222

Files:
  clang/include/clang/Analysis/MacroExpansionContext.h
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Analysis/MacroExpansionContext.cpp
  clang/unittests/Analysis/CMakeLists.txt
  clang/unittests/Analysis/MacroExpansionContextTest.cpp

Index: clang/unittests/Analysis/MacroExpansionContextTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -0,0 +1,424 @@
+//===- unittests/Analysis/MacroExpansionContextTest.cpp - -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/MacroExpansionContext.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Parse/Parser.h"
+#include "llvm/ADT/SmallString.h"
+#include "gtest/gtest.h"
+
+// static bool HACK_EnableDebugInUnitTest = (::llvm::DebugFlag = true);
+
+namespace clang {
+namespace analysis {
+namespace {
+
+class MacroExpansionContextTest : public ::testing::Test {
+protected:
+  MacroExpansionContextTest()
+  : InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
+FileMgr(FileSystemOptions(), InMemoryFileSystem),
+DiagID(new DiagnosticIDs()), DiagOpts(new DiagnosticOptions()),
+Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions()) {
+TargetOpts->Triple = "x86_64-pc-linux-unknown";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+LangOpts.CPlusPlus20 = 1; // For __VA_OPT__
+  }
+
+  IntrusiveRefCntPtr InMemoryFileSystem;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  IntrusiveRefCntPtr DiagOpts;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+
+  std::unique_ptr
+  getMacroExpansionContextFor(StringRef SourceText) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+TrivialModuleLoader ModLoader;
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+Diags, LangOpts, Target.get());
+Preprocessor PP(std::make_shared(), Diags, LangOpts,
+SourceMgr, HeaderInfo, ModLoader,
+/*IILookup =*/nullptr,
+/*OwnsHeaderSearch =*/false);
+
+PP.Initialize(*Target);
+auto Ctx = std::make_unique(LangOpts);
+Ctx->registerForPreprocessor(PP);
+
+// Lex source text.
+PP.EnterMainSourceFile();
+
+while (true) {
+  Token Tok;
+  PP.Lex(Tok);
+  if (Tok.is(tok::eof))
+break;
+}
+
+// Callbacks have been executed at this point.
+return Ctx;
+  }
+
+  /// Returns the expansion location to main file at the given row and column.
+  SourceLocation at(unsigned row, unsigned col) const {
+SourceLocation Loc =
+SourceMgr.translateLineCol(SourceMgr.getMainFileID(), row, col);
+return SourceMgr.getExpansionLoc(Loc);
+  }
+
+  static std::string dumpExpandedTexts(const MacroExpansionContext ) {
+std::string Buf;
+llvm::raw_string_ostream OS{Buf};
+Ctx.dumpExpandedTextsToStream(OS);
+return OS.str();
+  }
+
+  static std::string dumpExpansionRanges(const MacroExpansionContext ) {
+std::string Buf;
+llvm::raw_string_ostream OS{Buf};
+Ctx.dumpExpansionRangesToStream(OS);
+return OS.str();
+  }
+};
+
+TEST_F(MacroExpansionContextTest, IgnoresPragmas) {
+  // No-crash during lexing.
+  const auto Ctx = getMacroExpansionContextFor(R"code(
+  _Pragma("pack(push, 1)")
+  _Pragma("pack(pop, 1)")
+  )code");
+  // After preprocessing:
+  // #pragma pack(push, 1)
+  // #pragma pack(pop, 1)
+
+  EXPECT_EQ("\n=== ExpandedTokens ===\n",
+dumpExpandedTexts(*Ctx));
+  EXPECT_EQ("\n=== 

[PATCH] D94673: [analyzer][CTU] API for CTU macro expansions

2021-02-22 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG38b185832e04: [analyzer][CTU] API for CTU macro expansions 
(authored by steakhal, committed by Balazs Benics 
balazsben...@sigmatechnology.se).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94673/new/

https://reviews.llvm.org/D94673

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/test/Analysis/plist-macros-with-expansion-ctu.c
  clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -91,26 +91,6 @@
   *Success = NewFD && NewFD->hasBody() && !OrigFDHasBody;
 
   if (NewFD) {
-// Check GetImportedFromSourceLocation.
-llvm::Optional> SLocResult =
-CTU.getImportedFromSourceLocation(NewFD->getLocation());
-EXPECT_TRUE(SLocResult);
-if (SLocResult) {
-  SourceLocation OrigSLoc = (*SLocResult).first;
-  ASTUnit *OrigUnit = (*SLocResult).second;
-  // OrigUnit is created internally by CTU (is not the
-  // ASTWithDefinition).
-  TranslationUnitDecl *OrigTU =
-  OrigUnit->getASTContext().getTranslationUnitDecl();
-  const FunctionDecl *FDWithDefinition = FindFInTU(OrigTU);
-  EXPECT_TRUE(FDWithDefinition);
-  if (FDWithDefinition) {
-EXPECT_EQ(FDWithDefinition->getName(), "f");
-EXPECT_TRUE(FDWithDefinition->isThisDeclarationADefinition());
-EXPECT_EQ(OrigSLoc, FDWithDefinition->getLocation());
-  }
-}
-
 // Check parent map.
 const DynTypedNodeList ParentsAfterImport =
 Ctx.getParentMapContext().getParents(*FD);
Index: clang/test/Analysis/plist-macros-with-expansion-ctu.c
===
--- clang/test/Analysis/plist-macros-with-expansion-ctu.c
+++ clang/test/Analysis/plist-macros-with-expansion-ctu.c
@@ -2,13 +2,13 @@
 // RUN: mkdir -p %t/ctudir
 // RUN: %clang_cc1 -emit-pch -o %t/ctudir/plist-macros-ctu.c.ast %S/Inputs/plist-macros-ctu.c
 // RUN: cp %S/Inputs/plist-macros-with-expansion-ctu.c.externalDefMap.txt %t/ctudir/externalDefMap.txt
-
+//
 // RUN: %clang_analyze_cc1 -analyzer-checker=core \
 // RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
 // RUN:   -analyzer-config ctu-dir=%t/ctudir \
 // RUN:   -analyzer-config expand-macros=true \
 // RUN:   -analyzer-output=plist-multi-file -o %t.plist -verify %s
-// XFAIL: *
+//
 // Check the macro expansions from the plist output here, to make the test more
 // understandable.
 //   RUN: FileCheck --input-file=%t.plist %s
@@ -23,25 +23,30 @@
   F3();
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
-// CHECK: nameM1
-// CHECK-NEXT: expansion*Z = (int *)0
-
+// FIXME: Macro expansion for other TUs should also work.
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT: 
 
 void test1() {
   int *X;
   F1();
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
-// CHECK: nameM
-// CHECK-NEXT: expansion*X = (int *)0
+
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT: 
 
 void test2() {
   int *X;
   F2();
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
-// CHECK: nameM
-// CHECK-NEXT: expansion*Y = (int *)0
+
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT: 
 
 #define M F1()
 
@@ -50,10 +55,20 @@
   M;
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
-// CHECK: nameM
-// CHECK-NEXT: expansionF1(X)
-// CHECK: nameM
-// CHECK-NEXT: expansion*X = (int *)0
+// Macro expansions for the main TU still works, even in CTU mode.
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT:  
+// CHECK-NEXT:   location
+// CHECK-NEXT:   
+// CHECK-NEXT:line55
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   nameM
+// CHECK-NEXT:   expansionF1 (X )
+// CHECK-NEXT:  
+// CHECK-NEXT: 
 
 #undef M
 #define M F2()
@@ -64,10 +79,19 @@
   *X = 1; // expected-warning{{Dereference of null pointer}}
 }
 
-// CHECK: nameM
-// CHECK-NEXT: expansionF2(X)
-// CHECK: nameM
-// CHECK-NEXT: expansion*Y = (int *)0
+// CHECK:  macro_expansions
+// CHECK-NEXT: 
+// CHECK-NEXT:  
+// CHECK-NEXT:   location
+// CHECK-NEXT:   
+// CHECK-NEXT:line78
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   nameM
+// CHECK-NEXT:   expansionF2 (X )
+// CHECK-NEXT:  
+// CHECK-NEXT: 
 
 void test_h() {
   int *X;
@@ -75,5 +99,6 @@
   *X = 1; // expected-warning{{Dereference 

[PATCH] D93223: [analyzer] Create MacroExpansionContext member in AnalysisConsumer

2021-02-22 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c58fb6ba04e: [analyzer] Create MacroExpansionContext member 
in AnalysisConsumer (authored by steakhal, committed by Balazs Benics 
balazsben...@sigmatechnology.se).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93223/new/

https://reviews.llvm.org/D93223

Files:
  clang/include/clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h
  clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -20,6 +20,7 @@
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CallGraph.h"
 #include "clang/Analysis/CodeInjector.h"
+#include "clang/Analysis/MacroExpansionContext.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
@@ -98,6 +99,8 @@
   /// working with a PCH file.
   SetOfDecls LocalTUDecls;
 
+  MacroExpansionContext MacroExpansions;
+
   // Set of PathDiagnosticConsumers.  Owned by AnalysisManager.
   PathDiagnosticConsumers PathConsumers;
 
@@ -122,7 +125,8 @@
CodeInjector *injector)
   : RecVisitorMode(0), RecVisitorBR(nullptr), Ctx(nullptr),
 PP(CI.getPreprocessor()), OutDir(outdir), Opts(std::move(opts)),
-Plugins(plugins), Injector(injector), CTU(CI) {
+Plugins(plugins), Injector(injector), CTU(CI),
+MacroExpansions(CI.getLangOpts()) {
 DigestAnalyzerOptions();
 if (Opts->PrintStats || Opts->ShouldSerializeStats) {
   AnalyzerTimers = std::make_unique(
@@ -136,6 +140,9 @@
   *AnalyzerTimers);
   llvm::EnableStatistics(/* PrintOnExit= */ false);
 }
+
+if (Opts->ShouldDisplayMacroExpansions)
+  MacroExpansions.registerForPreprocessor(PP);
   }
 
   ~AnalysisConsumer() override {
@@ -150,7 +157,8 @@
   break;
 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)\
   case PD_##NAME:  \
-CREATEFN(Opts->getDiagOpts(), PathConsumers, OutDir, PP, CTU); \
+CREATEFN(Opts->getDiagOpts(), PathConsumers, OutDir, PP, CTU,  \
+ MacroExpansions); \
 break;
 #include "clang/StaticAnalyzer/Core/Analyses.def"
 default:
Index: clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/Analysis/MacroExpansionContext.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
@@ -138,8 +139,9 @@
 
 void ento::createTextPathDiagnosticConsumer(
 PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers ,
-const std::string , const clang::Preprocessor ,
-const cross_tu::CrossTranslationUnitContext ) {
+const std::string , const Preprocessor ,
+const cross_tu::CrossTranslationUnitContext ,
+const MacroExpansionContext ) {
   C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
  PP.getLangOpts(),
  /*ShouldDisplayPathNotes=*/true));
@@ -147,8 +149,9 @@
 
 void ento::createTextMinimalPathDiagnosticConsumer(
 PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers ,
-const std::string , const clang::Preprocessor ,
-const cross_tu::CrossTranslationUnitContext ) {
+const std::string , const Preprocessor ,
+const cross_tu::CrossTranslationUnitContext ,
+const MacroExpansionContext ) {
   C.emplace_back(new TextDiagnostics(std::move(DiagOpts), PP.getDiagnostics(),
  PP.getLangOpts(),
  /*ShouldDisplayPathNotes=*/false));
Index: clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/Analysis/MacroExpansionContext.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include 

[PATCH] D107952: [AMDGPU][OpenMP] Use llvm-link to link ocml libraries

2021-08-13 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG60e07a956862: [AMDGPU][OpenMP] Use llvm-link to link ocml 
libraries (authored by Pushpinder Singh pushpinderdhaliwa...@gmail.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107952/new/

https://reviews.llvm.org/D107952

Files:
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.h
  clang/test/Driver/amdgpu-openmp-toolchain.c

Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -76,4 +76,4 @@
 // CHECK-EMIT-LLVM-IR: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-emit-llvm"
 
 // RUN: env LIBRARY_PATH=%S/Inputs/hip_dev_lib %clang -### -target x86_64-pc-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -lm --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode %s 2>&1 | FileCheck %s --check-prefix=CHECK-LIB-DEVICE
-// CHECK-LIB-DEVICE: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-mlink-builtin-bitcode"{{.*}}libomptarget-amdgcn-gfx803.bc"{{.*}}"-mlink-builtin-bitcode"{{.*}}ocml.bc" "-mlink-builtin-bitcode"{{.*}}ockl.bc" "-mlink-builtin-bitcode"{{.*}}oclc_daz_opt_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_unsafe_math_off.bc" "-mlink-builtin-bitcode"{{.*}}oclc_finite_only_off.bc" "-mlink-builtin-bitcode"{{.*}}oclc_correctly_rounded_sqrt_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_wavefrontsize64_on.bc" "-mlink-builtin-bitcode"{{.*}}oclc_isa_version_803.bc"
+// CHECK-LIB-DEVICE: {{.*}}llvm-link{{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
Index: clang/lib/Driver/ToolChains/AMDGPUOpenMP.h
===
--- clang/lib/Driver/ToolChains/AMDGPUOpenMP.h
+++ clang/lib/Driver/ToolChains/AMDGPUOpenMP.h
@@ -16,6 +16,10 @@
 namespace clang {
 namespace driver {
 
+namespace toolchains {
+class AMDGPUOpenMPToolChain;
+}
+
 namespace tools {
 
 namespace AMDGCN {
@@ -35,11 +39,11 @@
 
 private:
   /// \return llvm-link output file name.
-  const char *constructLLVMLinkCommand(Compilation , const JobAction ,
-   const InputInfoList ,
-   const llvm::opt::ArgList ,
-   llvm::StringRef SubArchName,
-   llvm::StringRef OutputFilePrefix) const;
+  const char *constructLLVMLinkCommand(
+  const toolchains::AMDGPUOpenMPToolChain , Compilation ,
+  const JobAction , const InputInfoList ,
+  const llvm::opt::ArgList , llvm::StringRef SubArchName,
+  llvm::StringRef OutputFilePrefix) const;
 
   /// \return llc output file name.
   const char *constructLlcCommand(Compilation , const JobAction ,
Index: clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -86,14 +86,34 @@
 } // namespace
 
 const char *AMDGCN::OpenMPLinker::constructLLVMLinkCommand(
-Compilation , const JobAction , const InputInfoList ,
-const ArgList , StringRef SubArchName,
-StringRef OutputFilePrefix) const {
+const toolchains::AMDGPUOpenMPToolChain , Compilation ,
+const JobAction , const InputInfoList , const ArgList ,
+StringRef SubArchName, StringRef OutputFilePrefix) const {
   ArgStringList CmdArgs;
 
   for (const auto  : Inputs)
 if (II.isFilename())
   CmdArgs.push_back(II.getFilename());
+
+  if (Args.hasArg(options::OPT_l)) {
+auto Lm = Args.getAllArgValues(options::OPT_l);
+bool HasLibm = false;
+for (auto  : Lm) {
+  if (Lib == "m") {
+HasLibm = true;
+break;
+  }
+}
+
+if (HasLibm) {
+  SmallVector BCLibs =
+  AMDGPUOpenMPTC.getCommonDeviceLibNames(Args, SubArchName.str());
+  llvm::for_each(BCLibs, [&](StringRef BCFile) {
+CmdArgs.push_back(Args.MakeArgString(BCFile));
+  });
+}
+  }
+
   // Add an intermediate output file.
   CmdArgs.push_back("-o");
   const char *OutputFileName =
@@ -182,8 +202,8 @@
   assert(Prefix.length() && "no linker inputs are files ");
 
   // Each command outputs different files.
-  const char *LLVMLinkCommand =
-  constructLLVMLinkCommand(C, JA, Inputs, Args, GPUArch, Prefix);
+  const char *LLVMLinkCommand = constructLLVMLinkCommand(
+  AMDGPUOpenMPTC, C, JA, Inputs, Args, GPUArch, Prefix);
 
   // Produce readable assembly if save-temps is enabled.
   if (C.getDriver().isSaveTempsEnabled())
@@ -234,27 

[PATCH] D108552: [OpenMP][AMDGCN] Enable complex functions

2021-08-24 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07e85823aa75: [OpenMP][AMDGCN] Enable complex functions 
(authored by Pushpinder Singh pushpinderdhaliwa...@gmail.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108552/new/

https://reviews.llvm.org/D108552

Files:
  clang/lib/Headers/__clang_cuda_complex_builtins.h
  clang/lib/Headers/openmp_wrappers/complex
  clang/lib/Headers/openmp_wrappers/complex.h
  clang/test/Headers/amdgcn-openmp-device-math-complex.c

Index: clang/test/Headers/amdgcn-openmp-device-math-complex.c
===
--- /dev/null
+++ clang/test/Headers/amdgcn-openmp-device-math-complex.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -x c -fopenmp -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -x c -fopenmp -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -o - | FileCheck %s --check-prefixes=CHECK
+
+#include 
+
+void test_complex_f64(double _Complex a) {
+// CHECK-LABEL: define {{.*}}test_complex_f64
+#pragma omp target
+  {
+// CHECK: call { double, double } @__divdc3
+// CHECK: call { double, double } @__muldc3
+(void)(a * (a / a));
+  }
+}
+
+// CHECK: define weak {{.*}} @__divdc3
+// CHECK-DAG: call double @__ocml_fabs_f64(
+// CHECK-DAG: call i32 @__ocml_isnan_f64(
+// CHECK-DAG: call i32 @__ocml_isfinite_f64(
+// CHECK-DAG: call double @__ocml_copysign_f64(
+// CHECK-DAG: call double @__ocml_scalbn_f64(
+// CHECK-DAG: call double @__ocml_logb_f64(
+
+// CHECK: define weak {{.*}} @__muldc3
+// CHECK-DAG: call i32 @__ocml_isnan_f64(
+// CHECK-DAG: call i32 @__ocml_isinf_f64(
+// CHECK-DAG: call double @__ocml_copysign_f64(
+
+void test_complex_f32(float _Complex a) {
+// CHECK-LABEL: define {{.*}}test_complex_f32
+#pragma omp target
+  {
+// CHECK: call [2 x i32] @__divsc3
+// CHECK: call [2 x i32] @__mulsc3
+(void)(a * (a / a));
+  }
+}
+
+// CHECK: define weak {{.*}} @__divsc3
+// CHECK-DAG: call float @__ocml_fabs_f32(
+// CHECK-DAG: call i32 @__ocml_isnan_f32(
+// CHECK-DAG: call i32 @__ocml_isfinite_f32(
+// CHECK-DAG: call float @__ocml_copysign_f32(
+// CHECK-DAG: call float @__ocml_scalbn_f32(
+// CHECK-DAG: call float @__ocml_logb_f32(
+
+// CHECK: define weak {{.*}} @__mulsc3
+// CHECK-DAG: call i32 @__ocml_isnan_f32(
+// CHECK-DAG: call i32 @__ocml_isinf_f32(
+// CHECK-DAG: call float @__ocml_copysign_f32(
Index: clang/lib/Headers/openmp_wrappers/complex.h
===
--- clang/lib/Headers/openmp_wrappers/complex.h
+++ clang/lib/Headers/openmp_wrappers/complex.h
@@ -17,10 +17,19 @@
 // We require math functions in the complex builtins below.
 #include 
 
+#ifdef __NVPTX__
 #define __OPENMP_NVPTX__
 #include <__clang_cuda_complex_builtins.h>
 #undef __OPENMP_NVPTX__
 #endif
 
+#ifdef __AMDGCN__
+#define __OPENMP_AMDGCN__
+#include <__clang_cuda_complex_builtins.h>
+#undef __OPENMP_AMDGCN__
+#endif
+
+#endif
+
 // Grab the host header too.
 #include_next 
Index: clang/lib/Headers/openmp_wrappers/complex
===
--- clang/lib/Headers/openmp_wrappers/complex
+++ clang/lib/Headers/openmp_wrappers/complex
@@ -17,9 +17,18 @@
 // We require std::math functions in the complex builtins below.
 #include 
 
+#ifdef __NVPTX__
 #define __OPENMP_NVPTX__
 #include <__clang_cuda_complex_builtins.h>
 #undef __OPENMP_NVPTX__
+#endif // __NVPTX__
+
+#ifdef __AMDGCN__
+#define __OPENMP_AMDGCN__
+#include <__clang_cuda_complex_builtins.h>
+#undef __OPENMP_AMDGCN__
+#endif // __AMDGCN__
+
 #endif
 
 // Grab the host header too.
@@ -43,4 +52,4 @@
 
 #pragma omp end declare variant
 
-#endif
+#endif // _LIBCPP_STD_VER
Index: clang/lib/Headers/__clang_cuda_complex_builtins.h
===
--- clang/lib/Headers/__clang_cuda_complex_builtins.h
+++ clang/lib/Headers/__clang_cuda_complex_builtins.h
@@ -16,7 +16,7 @@
 // to work with CUDA and OpenMP target offloading [in C and C++ mode].)
 
 #pragma push_macro("__DEVICE__")
-#ifdef __OPENMP_NVPTX__
+#if defined(__OPENMP_NVPTX__) || defined(__OPENMP_AMDGCN__)
 #pragma omp declare target
 #define __DEVICE__ __attribute__((noinline, nothrow, cold, weak))
 #else
@@ -26,7 +26,7 @@
 // To make the algorithms available for C and C++ in CUDA and OpenMP we select
 // different but equivalent function versions. TODO: For OpenMP we currently
 // select the native builtins as 

[PATCH] D109344: [AMDGPU][OpenMP] Use complex definitions from complex_cmath.h

2021-09-08 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG12dcbf913c49: [AMDGPU][OpenMP] Use complex definitions from 
complex_cmath.h (authored by Pushpinder Singh 
pushpinderdhaliwa...@gmail.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109344/new/

https://reviews.llvm.org/D109344

Files:
  clang/lib/Headers/openmp_wrappers/complex
  clang/test/Headers/amdgcn-openmp-device-math-complex.cpp

Index: clang/test/Headers/amdgcn-openmp-device-math-complex.cpp
===
--- /dev/null
+++ clang/test/Headers/amdgcn-openmp-device-math-complex.cpp
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -verify -internal-isystem %S/Inputs/include -fopenmp -x c++ -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/Inputs/include -fopenmp -x c++ -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -aux-triple x86_64-unknown-unknown -o - | FileCheck %s
+// expected-no-diagnostics
+
+#include 
+#include 
+
+// CHECK: define weak {{.*}} @__muldc3
+// CHECK-DAG: call i32 @__ocml_isnan_f64(
+// CHECK-DAG: call i32 @__ocml_isinf_f64(
+
+// CHECK: define weak {{.*}} @__mulsc3
+// CHECK-DAG: call i32 @__ocml_isnan_f32(
+// CHECK-DAG: call i32 @__ocml_isinf_f32(
+// CHECK-DAG: call float @__ocml_copysign_f32(
+
+// CHECK: define weak {{.*}} @__divdc3
+// CHECK-DAG: call i32 @__ocml_isnan_f64(
+// CHECK-DAG: call i32 @__ocml_isinf_f64(
+// CHECK-DAG: call i32 @__ocml_isfinite_f64(
+// CHECK-DAG: call double @__ocml_copysign_f64(
+// CHECK-DAG: call double @__ocml_scalbn_f64(
+// CHECK-DAG: call double @__ocml_fabs_f64(
+// CHECK-DAG: call double @__ocml_logb_f64(
+
+// CHECK: define weak {{.*}} @__divsc3
+// CHECK-DAG: call i32 @__ocml_isnan_f32(
+// CHECK-DAG: call i32 @__ocml_isinf_f32(
+// CHECK-DAG: call i32 @__ocml_isfinite_f32(
+// CHECK-DAG: call float @__ocml_copysign_f32(
+// CHECK-DAG: call float @__ocml_scalbn_f32(
+// CHECK-DAG: call float @__ocml_fabs_f32(
+// CHECK-DAG: call float @__ocml_logb_f32(
+
+// We actually check that there are no declarations of non-OpenMP functions.
+// That is, as long as we don't call an unkown function with a name that
+// doesn't start with '__' we are good :)
+
+// CHECK-NOT: declare.*@[^_]
+
+void test_scmplx(std::complex a) {
+#pragma omp target
+  {
+(void)(a * (a / a));
+  }
+}
+
+void test_dcmplx(std::complex a) {
+#pragma omp target
+  {
+(void)(a * (a / a));
+  }
+}
+
+template 
+std::complex test_template_math_calls(std::complex a) {
+  decltype(a) r = a;
+#pragma omp target
+  {
+r = std::sin(r);
+r = std::cos(r);
+r = std::exp(r);
+r = std::atan(r);
+r = std::acos(r);
+  }
+  return r;
+}
+
+std::complex test_scall(std::complex a) {
+  decltype(a) r;
+#pragma omp target
+  {
+r = std::sin(a);
+  }
+  return test_template_math_calls(r);
+}
+
+std::complex test_dcall(std::complex a) {
+  decltype(a) r;
+#pragma omp target
+  {
+r = std::exp(a);
+  }
+  return test_template_math_calls(r);
+}
Index: clang/lib/Headers/openmp_wrappers/complex
===
--- clang/lib/Headers/openmp_wrappers/complex
+++ clang/lib/Headers/openmp_wrappers/complex
@@ -45,7 +45,7 @@
 #ifndef _LIBCPP_STD_VER
 
 #pragma omp begin declare variant match(   \
-device = {arch(nvptx, nvptx64)},   \
+device = {arch(amdgcn, nvptx, nvptx64)},   \
 implementation = {extension(match_any, allow_templates)})
 
 #include 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105091: [RISCV] Pass -u to linker correctly.

2021-07-14 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5635d2a56dab: [RISCV] Pass -u to linker correctly. (authored 
by Kito Cheng kito.ch...@sifive.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105091/new/

https://reviews.llvm.org/D105091

Files:
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/test/Driver/riscv-args.c


Index: clang/test/Driver/riscv-args.c
===
--- clang/test/Driver/riscv-args.c
+++ clang/test/Driver/riscv-args.c
@@ -1,7 +1,6 @@
 // Check the arguments are correctly passed
 
 // Make sure -T is the last with gcc-toolchain option
-// RUN: %clang -### -target riscv32 \
-// RUN:   --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds %s 2>&1 \
+// RUN: %clang -### -target riscv32 --gcc-toolchain= -Xlinker --defsym=FOO=10 
-T a.lds -u foo %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LD %s
-// CHECK-LD: {{.*}} "--defsym=FOO=10" {{.*}} "-T" "a.lds"
+// CHECK-LD: {{.*}} "--defsym=FOO=10" {{.*}} "-u" "foo" {{.*}} "-T" "a.lds"
Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -184,6 +184,7 @@
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
+  Args.AddAllArgs(CmdArgs, options::OPT_u);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
   Args.AddAllArgs(CmdArgs,
   {options::OPT_T_Group, options::OPT_e, options::OPT_s,


Index: clang/test/Driver/riscv-args.c
===
--- clang/test/Driver/riscv-args.c
+++ clang/test/Driver/riscv-args.c
@@ -1,7 +1,6 @@
 // Check the arguments are correctly passed
 
 // Make sure -T is the last with gcc-toolchain option
-// RUN: %clang -### -target riscv32 \
-// RUN:   --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds %s 2>&1 \
+// RUN: %clang -### -target riscv32 --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds -u foo %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LD %s
-// CHECK-LD: {{.*}} "--defsym=FOO=10" {{.*}} "-T" "a.lds"
+// CHECK-LD: {{.*}} "--defsym=FOO=10" {{.*}} "-u" "foo" {{.*}} "-T" "a.lds"
Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -184,6 +184,7 @@
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
+  Args.AddAllArgs(CmdArgs, options::OPT_u);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
   Args.AddAllArgs(CmdArgs,
   {options::OPT_T_Group, options::OPT_e, options::OPT_s,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107720: [analyzer] Cleanup a FIXME in SValBuilder.cpp

2021-08-10 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd39ebdae674c: [analyzer] Cleanup a FIXME in SValBuilder.cpp 
(authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107720/new/

https://reviews.llvm.org/D107720

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/solver-sym-simplification-bool.cpp


Index: clang/test/Analysis/solver-sym-simplification-bool.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int ) {
+  int *p =  // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt  = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);


Index: clang/test/Analysis/solver-sym-simplification-bool.cpp
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int ) {
+  int *p =  // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt  = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-10-17 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGff13189c5d0d: [RISCV] Unify the arch string parsing logic to 
to RISCVISAInfo. (authored by Kito Cheng kito.ch...@sifive.com).

Changed prior to commit:
  https://reviews.llvm.org/D105168?vs=379329=380228#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105168/new/

https://reviews.llvm.org/D105168

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-abi.c
  clang/test/Driver/riscv-arch.c
  clang/test/Driver/riscv-features.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/attribute-with-insts.s
  llvm/test/MC/RISCV/invalid-attribute.s

Index: llvm/test/MC/RISCV/invalid-attribute.s
===
--- llvm/test/MC/RISCV/invalid-attribute.s
+++ llvm/test/MC/RISCV/invalid-attribute.s
@@ -7,10 +7,10 @@
 # RUN: not llvm-mc %s -triple=riscv64 -filetype=asm 2>&1 | FileCheck %s
 
 .attribute arch, "foo"
-# CHECK: [[@LINE-1]]:18: error: bad arch string foo
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'foo', string must begin with rv32{i,e,g} or rv64{i,g}
 
 .attribute arch, "rv32i2p0_y2p0"
-# CHECK: [[@LINE-1]]:18: error: bad arch string y2p0
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'rv32i2p0_y2p0', invalid standard user-level extension 'y'
 
 .attribute stack_align, "16"
 # CHECK: [[@LINE-1]]:25: error: expected numeric constant
Index: llvm/test/MC/RISCV/attribute-with-insts.s
===
--- llvm/test/MC/RISCV/attribute-with-insts.s
+++ llvm/test/MC/RISCV/attribute-with-insts.s
@@ -10,7 +10,7 @@
 # RUN:   | llvm-objdump --triple=riscv64 -d -M no-aliases - \
 # RUN:   | FileCheck -check-prefix=CHECK-INST %s
 
-.attribute arch, "rv64i2p0_m2p0_a2p0_d2p0_c2p0"
+.attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 # CHECK-INST: lr.w t0, (t1)
 lr.w t0, (t1)
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -9,9 +9,6 @@
 .attribute arch, "rv32i2"
 # CHECK: attribute  5, "rv32i2p0"
 
-.attribute arch, "rv32i2p"
-# CHECK: attribute  5, "rv32i2p0"
-
 .attribute arch, "rv32i2p0"
 # CHECK: attribute  5, "rv32i2p0"
 
@@ -33,11 +30,11 @@
 .attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
-.attribute arch, "rv32ima2p_fdc"
+.attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba1p0"
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
===
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
@@ -11,9 +11,11 @@
 //===--===//
 
 #include "RISCVTargetStreamer.h"
+#include "RISCVBaseInfo.h"
 #include "RISCVMCTargetDesc.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/RISCVAttributes.h"
+#include "llvm/Support/RISCVISAInfo.h"
 
 using namespace llvm;
 
@@ -43,53 +45,19 @@
   else
 emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_16);
 
-  std::string Arch = "rv32";
-  if (STI.hasFeature(RISCV::Feature64Bit))
-Arch = "rv64";
-  if (STI.hasFeature(RISCV::FeatureRV32E))
-Arch += "e1p9";
-  else
-Arch += "i2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtM))
-Arch += "_m2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtA))
-Arch += "_a2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtF))
-Arch += "_f2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtD))
-Arch += "_d2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtC))
-Arch += "_c2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtV))
-Arch += "_v0p10";
-  if (STI.hasFeature(RISCV::FeatureStdExtZfh))
-Arch += "_zfh0p1";
-  if (STI.hasFeature(RISCV::FeatureStdExtZba))
-Arch += "_zba1p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtZbb))
-Arch += "_zbb1p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtZbc))
-Arch += "_zbc1p0";
-  if 

[PATCH] D110625: [analyzer] canonicalize special case of structure/pointer deref

2021-10-06 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb29186c08ae2: [analyzer] canonicalize special case of 
structure/pointer deref (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110625/new/

https://reviews.llvm.org/D110625

Files:
  clang/lib/StaticAnalyzer/Core/Store.cpp
  clang/test/Analysis/ptr-arith.c


Index: clang/test/Analysis/ptr-arith.c
===
--- clang/test/Analysis/ptr-arith.c
+++ clang/test/Analysis/ptr-arith.c
@@ -2,6 +2,7 @@
 // RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,alpha.core.PointerSub,debug.ExprInspection
 -analyzer-store=region -Wno-pointer-to-int-cast -verify -triple 
i686-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config 
eagerly-assume=false %s
 
 void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
 
 void f1() {
   int a[10];
@@ -330,3 +331,59 @@
   simd_float2 x = {0, 1};
   return x[1]; // no-warning
 }
+
+struct s {
+  int v;
+};
+
+// These three expressions should produce the same sym vals.
+void struct_pointer_canon(struct s *ps) {
+  struct s ss = *ps;
+  clang_analyzer_dump((*ps).v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps[0].v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps->v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_eval((*ps).v == ps[0].v); // expected-warning{{TRUE}}
+  clang_analyzer_eval((*ps).v == ps->v);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ps[0].v == ps->v);   // expected-warning{{TRUE}}
+}
+
+void struct_pointer_canon_bidim(struct s **ps) {
+  struct s ss = **ps;
+  clang_analyzer_eval(&(ps[0][0].v) == &((*ps)->v)); // 
expected-warning{{TRUE}}
+}
+
+typedef struct s T1;
+typedef struct s T2;
+void struct_pointer_canon_typedef(T1 *ps) {
+  T2 ss = *ps;
+  clang_analyzer_dump((*ps).v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps[0].v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps->v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_eval((*ps).v == ps[0].v); // expected-warning{{TRUE}}
+  clang_analyzer_eval((*ps).v == ps->v);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ps[0].v == ps->v);   // expected-warning{{TRUE}}
+}
+
+void struct_pointer_canon_bidim_typedef(T1 **ps) {
+  T2 ss = **ps;
+  clang_analyzer_eval(&(ps[0][0].v) == &((*ps)->v)); // 
expected-warning{{TRUE}}
+}
+
+void struct_pointer_canon_const(const struct s *ps) {
+  struct s ss = *ps;
+  clang_analyzer_dump((*ps).v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps[0].v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps->v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_eval((*ps).v == ps[0].v); // expected-warning{{TRUE}}
+  clang_analyzer_eval((*ps).v == ps->v);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ps[0].v == ps->v);   // expected-warning{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -442,6 +442,19 @@
 
 SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset,
 SVal Base) {
+
+  // Special case, if index is 0, return the same type as if
+  // this was not an array dereference.
+  if (Offset.isZeroConstant()) {
+QualType BT = Base.getType(this->Ctx);
+if (!BT.isNull() && !elementType.isNull()) {
+  QualType PointeeTy = BT->getPointeeType();
+  if (!PointeeTy.isNull() &&
+  PointeeTy.getCanonicalType() == elementType.getCanonicalType())
+return Base;
+}
+  }
+
   // If the base is an unknown or undefined value, just return it back.
   // FIXME: For absolute pointer addresses, we just return that value back as
   //  well, although in reality we should return the offset added to that


Index: clang/test/Analysis/ptr-arith.c
===
--- clang/test/Analysis/ptr-arith.c
+++ clang/test/Analysis/ptr-arith.c
@@ -2,6 +2,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,alpha.core.PointerSub,debug.ExprInspection -analyzer-store=region -Wno-pointer-to-int-cast -verify -triple i686-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s
 
 void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
 
 void f1() {
   int a[10];
@@ -330,3 +331,59 @@
   simd_float2 x = {0, 1};
   return x[1]; // no-warning
 }
+
+struct s {
+  int v;
+};
+
+// These three 

[PATCH] D115901: [OpenMP][NFC] update status for 5.1 'fail' atomic extension

2021-12-17 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd976fb020428: [OpenMP][NFC] update status for 5.1 
fail atomic extension (authored by dreachem, committed by Chi-Chun, 
Chen chichunchen...@gmail.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115901/new/

https://reviews.llvm.org/D115901

Files:
  clang/docs/OpenMPSupport.rst


Index: clang/docs/OpenMPSupport.rst
===
--- clang/docs/OpenMPSupport.rst
+++ clang/docs/OpenMPSupport.rst
@@ -266,7 +266,7 @@
 
+==+==+==+===+
 | atomic extension | 'compare' clause on atomic construct  
   | :good:`worked on`| 
  |
 
+--+--+--+---+
-| atomic extension | 'fail' clause on atomic construct 
   | :none:`unclaimed`| 
  |
+| atomic extension | 'fail' clause on atomic construct 
   | :part:`worked on`| 
  |
 
+--+--+--+---+
 | base language| C++ attribute specifier syntax
   | :good:`done` | D105648 
  |
 
+--+--+--+---+


Index: clang/docs/OpenMPSupport.rst
===
--- clang/docs/OpenMPSupport.rst
+++ clang/docs/OpenMPSupport.rst
@@ -266,7 +266,7 @@
 +==+==+==+===+
 | atomic extension | 'compare' clause on atomic construct | :good:`worked on`|   |
 +--+--+--+---+
-| atomic extension | 'fail' clause on atomic construct| :none:`unclaimed`|   |
+| atomic extension | 'fail' clause on atomic construct| :part:`worked on`|   |
 +--+--+--+---+
 | base language| C++ attribute specifier syntax   | :good:`done` | D105648   |
 +--+--+--+---+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112420: [clang][ARM] PACBTI-M assembly support

2021-11-30 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5cff77c23f43: [clang][ARM] PACBTI-M assembly support 
(authored by stuij, committed by Zeno zeno@Zenos-MacBook-Pro.local).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112420/new/

https://reviews.llvm.org/D112420

Files:
  clang/test/Driver/armv8.1m.main.c
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/include/llvm/Support/ARMTargetParser.h
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMInstrThumb2.td
  llvm/lib/Target/ARM/ARMPredicates.td
  llvm/lib/Target/ARM/ARMRegisterInfo.td
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/lib/Target/ARM/ARMSystemRegister.td
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
  llvm/test/CodeGen/Thumb/high-reg-clobber.mir
  llvm/test/MC/ARM/armv8.1m-pacbti-error.s
  llvm/test/MC/ARM/armv8.1m-pacbti.s
  llvm/test/MC/ARM/implicit-it-generation-v8.s
  llvm/test/MC/Disassembler/ARM/armv8.1m-pacbti.txt

Index: llvm/test/MC/Disassembler/ARM/armv8.1m-pacbti.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/ARM/armv8.1m-pacbti.txt
@@ -0,0 +1,137 @@
+# RUN: llvm-mc -triple thumbv8.1m.main-arm-none-eabi -mattr=+pacbti -disassemble %s 2> /dev/null | FileCheck %s
+
+0x51,0xfb,0x02,0x0f
+0x5e,0xfb,0x0d,0xcf
+0xaf,0xf3,0x2d,0x80
+0x51,0xfb,0x12,0x0f
+0xaf,0xf3,0x0f,0x80
+0x61,0xfb,0x02,0xf0
+0x6e,0xfb,0x0d,0xfc
+0xaf,0xf3,0x1d,0x80
+0xaf,0xf3,0x0d,0x80
+0x80,0xf3,0x20,0x88
+0x80,0xf3,0x21,0x88
+0x80,0xf3,0x22,0x88
+0x80,0xf3,0x23,0x88
+0x80,0xf3,0x24,0x88
+0x80,0xf3,0x25,0x88
+0x80,0xf3,0x26,0x88
+0x80,0xf3,0x27,0x88
+0x80,0xf3,0xa0,0x88
+0x80,0xf3,0xa1,0x88
+0x80,0xf3,0xa2,0x88
+0x80,0xf3,0xa3,0x88
+0x80,0xf3,0xa4,0x88
+0x80,0xf3,0xa5,0x88
+0x80,0xf3,0xa6,0x88
+0x80,0xf3,0xa7,0x88
+0xef,0xf3,0x20,0x80
+0xef,0xf3,0x21,0x80
+0xef,0xf3,0x22,0x80
+0xef,0xf3,0x23,0x80
+0xef,0xf3,0x24,0x80
+0xef,0xf3,0x25,0x80
+0xef,0xf3,0x26,0x80
+0xef,0xf3,0x27,0x80
+0xef,0xf3,0xa0,0x80
+0xef,0xf3,0xa1,0x80
+0xef,0xf3,0xa2,0x80
+0xef,0xf3,0xa3,0x80
+0xef,0xf3,0xa4,0x80
+0xef,0xf3,0xa5,0x80
+0xef,0xf3,0xa6,0x80
+0xef,0xf3,0xa7,0x80
+
+# Test softfail encodings
+0xa7,0xf3,0x1d,0x80
+0xab,0xf3,0x1d,0x80
+0xad,0xf3,0x1d,0x80
+0xae,0xf3,0x1d,0x80
+0xaf,0xf3,0x1d,0x88
+0xaf,0xf3,0x1d,0xa0
+0xaf,0xf3,0x2d,0x80
+0xab,0xf3,0x2d,0x80
+0xad,0xf3,0x2d,0x80
+0xae,0xf3,0x2d,0x80
+0xaf,0xf3,0x2d,0x88
+0xaf,0xf3,0x2d,0xa0
+0xa7,0xf3,0x0f,0x80
+0xab,0xf3,0x0f,0x80
+0xad,0xf3,0x0f,0x80
+0xae,0xf3,0x0f,0x80
+0xaf,0xf3,0x0f,0x88
+0xaf,0xf3,0x0f,0xa0
+0xa7,0xf3,0x0d,0x80
+0xab,0xf3,0x0d,0x80
+0xad,0xf3,0x0d,0x80
+0xae,0xf3,0x0d,0x80
+0xaf,0xf3,0x0d,0x88
+0xaf,0xf3,0x0d,0xa0
+
+# CHECK: autg	r0, r1, r2
+# CHECK: autg r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: bxautr0, r1, r2
+# CHECK: bti
+# CHECK: pacg	r0, r1, r2
+# CHECK: pacg	r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: msr	pac_key_p_0, r0
+# CHECK: msr	pac_key_p_1, r0
+# CHECK: msr	pac_key_p_2, r0
+# CHECK: msr	pac_key_p_3, r0
+# CHECK: msr	pac_key_u_0, r0
+# CHECK: msr	pac_key_u_1, r0
+# CHECK: msr	pac_key_u_2, r0
+# CHECK: msr	pac_key_u_3, r0
+# CHECK: msr	pac_key_p_0_ns, r0
+# CHECK: msr	pac_key_p_1_ns, r0
+# CHECK: msr	pac_key_p_2_ns, r0
+# CHECK: msr	pac_key_p_3_ns, r0
+# CHECK: msr	pac_key_u_0_ns, r0
+# CHECK: msr	pac_key_u_1_ns, r0
+# CHECK: msr	pac_key_u_2_ns, r0
+# CHECK: msr	pac_key_u_3_ns, r0
+# CHECK: mrs	r0, pac_key_p_0
+# CHECK: mrs	r0, pac_key_p_1
+# CHECK: mrs	r0, pac_key_p_2
+# CHECK: mrs	r0, pac_key_p_3
+# CHECK: mrs	r0, pac_key_u_0
+# CHECK: mrs	r0, pac_key_u_1
+# CHECK: mrs	r0, pac_key_u_2
+# CHECK: mrs	r0, pac_key_u_3
+# CHECK: mrs	r0, pac_key_p_0_ns
+# CHECK: mrs	r0, pac_key_p_1_ns
+# CHECK: mrs	r0, pac_key_p_2_ns
+# CHECK: mrs	r0, pac_key_p_3_ns
+# CHECK: mrs	r0, pac_key_u_0_ns
+# CHECK: mrs	r0, pac_key_u_1_ns
+# CHECK: mrs	r0, pac_key_u_2_ns
+# CHECK: mrs	r0, pac_key_u_3_ns
+
+# Softfail encodings
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: bti
+# CHECK: bti
+# CHECK: bti
+# CHECK: bti
+# CHECK: bti
+# CHECK: bti
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
Index: llvm/test/MC/ARM/implicit-it-generation-v8.s
===
--- /dev/null
+++ llvm/test/MC/ARM/implicit-it-generation-v8.s
@@ -0,0 +1,9 @@
+@ RUN: llvm-mc -triple 

[PATCH] D105974: [analyzer] Do not assume that all pointers have the same bitwidth as void*

2021-07-16 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG918bda124120: [analyzer] Do not assume that all pointers 
have the same bitwidth as void* (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Changed prior to commit:
  https://reviews.llvm.org/D105974?vs=359163=359246#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105974/new/

https://reviews.llvm.org/D105974

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/solver-sym-simplification-ptr-bool.cl


Index: clang/test/Analysis/solver-sym-simplification-ptr-bool.cl
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-ptr-bool.cl
@@ -0,0 +1,30 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown -analyze 
-analyzer-checker=core %s
+
+// expected-no-diagnostics
+
+// This test case covers an issue found in the static analyzer
+// solver where pointer sizes were assumed. Pointer sizes may vary on other
+// architectures. This issue was originally discovered on a downstream,
+// custom target, this assert occurs on the custom target and this one
+// without the fix, and is fixed with this change.
+//
+// The assertion appears to be happening as a result of evaluating the
+// SymIntExpr (reg_$0) != 0U in VisitSymIntExpr located in
+// SimpleSValBuilder.cpp. The LHS is evaluated to 32b and the RHS is
+// evaluated to 16b. This eventually leads to the assertion in APInt.h.
+//
+// APInt.h:1151: bool llvm::APInt::operator==(const llvm::APInt &) const: 
Assertion `BitWidth == RHS.BitWidth && "Comparison requires equal bit widths"'
+// 
+void test1(__attribute__((address_space(256))) int * p) {
+  __attribute__((address_space(256))) int * q = p-1;
+  if (q) {}
+  if (q) {}
+  (void)q;
+}
+ 
+void test2(__attribute__((address_space(256))) int * p) {
+  __attribute__((address_space(256))) int * q = p-1;
+  q && q; 
+  q && q; 
+  (void)q;
+} 
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -712,9 +712,23 @@
   // symbols to use, only content metadata.
   return nonloc::SymbolVal(SymMgr.getExtentSymbol(FTR));
 
-if (const SymbolicRegion *SymR = R->getSymbolicBase())
-  return makeNonLoc(SymR->getSymbol(), BO_NE,
-BasicVals.getZeroWithPtrWidth(), CastTy);
+if (const SymbolicRegion *SymR = R->getSymbolicBase()) {
+  SymbolRef Sym = SymR->getSymbol();
+  QualType Ty = Sym->getType();
+  // This change is needed for architectures with varying
+  // pointer widths. See the amdgcn opencl reproducer with
+  // this change as an example: solver-sym-simplification-ptr-bool.cl
+  // FIXME: We could encounter a reference here,
+  //try returning a concrete 'true' since it might
+  //be easier on the solver.
+  // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
+  //and `getIntWithPtrWidth()` functions to prevent future
+  //confusion
+  const llvm::APSInt  = Ty->isReferenceType()
+ ? BasicVals.getZeroWithPtrWidth()
+ : BasicVals.getZeroWithTypeSize(Ty);
+  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+}
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);
   }


Index: clang/test/Analysis/solver-sym-simplification-ptr-bool.cl
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-ptr-bool.cl
@@ -0,0 +1,30 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown -analyze -analyzer-checker=core %s
+
+// expected-no-diagnostics
+
+// This test case covers an issue found in the static analyzer
+// solver where pointer sizes were assumed. Pointer sizes may vary on other
+// architectures. This issue was originally discovered on a downstream,
+// custom target, this assert occurs on the custom target and this one
+// without the fix, and is fixed with this change.
+//
+// The assertion appears to be happening as a result of evaluating the
+// SymIntExpr (reg_$0) != 0U in VisitSymIntExpr located in
+// SimpleSValBuilder.cpp. The LHS is evaluated to 32b and the RHS is
+// evaluated to 16b. This eventually leads to the assertion in APInt.h.
+//
+// APInt.h:1151: bool llvm::APInt::operator==(const llvm::APInt &) const: Assertion `BitWidth == RHS.BitWidth && "Comparison requires equal bit widths"'
+// 
+void test1(__attribute__((address_space(256))) int * p) {
+  __attribute__((address_space(256))) int * q = p-1;
+  if (q) {}
+  if (q) {}
+  (void)q;
+}
+ 
+void 

[PATCH] D106903: [dfsan][NFC] Describe how origin trace tracking works

2021-07-27 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc49df15c2788: [dfsan][NFC] Describe how origin trace 
tracking works (authored by Jianzhou Zhao jianzho...@google.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106903/new/

https://reviews.llvm.org/D106903

Files:
  clang/docs/DataFlowSanitizerDesign.rst


Index: clang/docs/DataFlowSanitizerDesign.rst
===
--- clang/docs/DataFlowSanitizerDesign.rst
+++ clang/docs/DataFlowSanitizerDesign.rst
@@ -135,6 +135,35 @@
 track of what labels they have used so far, picking one that is yet
 unused, etc).
 
+Origin tracking trace representation
+
+
+An origin tracking trace is a list of chains. Each chain has a stack trace
+where the DFSan runtime records a label propapation, and a pointer to its
+previous chain. The very first chain does not point to any chain.
+
+Every four 4-bytes aligned application bytes share a 4-byte origin trace ID. A
+4-byte origin trace ID contains a 4-bit depth and a 28-bit hash ID of a chain.
+
+A chain ID is calculated as a hash from a chain structure. A chain structure
+contains a stack ID and the previous chain ID. The chain head has a zero
+previous chain ID. A stack ID is a hash from a stack trace. The 4-bit depth
+limits the maximal length of a path. The environment variable 
``origin_history_size``
+can set the depth limit. Non-positive values mean unlimited. Its default value
+is 16. When reaching the limit, origin tracking ignores following propagation
+chains.
+
+The first chain of a trace starts by `dfsan_set_label` with non-zero labels. A
+new chain is appended at the end of a trace at stores or memory transfers when
+``-dfsan-track-origins`` is 1. Memory transfers include LLVM memory transfer
+instructions, glibc memcpy and memmove. When ``-dfsan-track-origins`` is 2, a
+new chain is also appended at loads.
+
+Other instructions do not create new chains, but simply propagate origin trace
+IDs. If an instruction has more than one operands with non-zero labels, the 
origin
+treace ID of the last operand with non-zero label is propagated to the result 
of
+the instruction.
+
 Memory layout and label management
 --
 


Index: clang/docs/DataFlowSanitizerDesign.rst
===
--- clang/docs/DataFlowSanitizerDesign.rst
+++ clang/docs/DataFlowSanitizerDesign.rst
@@ -135,6 +135,35 @@
 track of what labels they have used so far, picking one that is yet
 unused, etc).
 
+Origin tracking trace representation
+
+
+An origin tracking trace is a list of chains. Each chain has a stack trace
+where the DFSan runtime records a label propapation, and a pointer to its
+previous chain. The very first chain does not point to any chain.
+
+Every four 4-bytes aligned application bytes share a 4-byte origin trace ID. A
+4-byte origin trace ID contains a 4-bit depth and a 28-bit hash ID of a chain.
+
+A chain ID is calculated as a hash from a chain structure. A chain structure
+contains a stack ID and the previous chain ID. The chain head has a zero
+previous chain ID. A stack ID is a hash from a stack trace. The 4-bit depth
+limits the maximal length of a path. The environment variable ``origin_history_size``
+can set the depth limit. Non-positive values mean unlimited. Its default value
+is 16. When reaching the limit, origin tracking ignores following propagation
+chains.
+
+The first chain of a trace starts by `dfsan_set_label` with non-zero labels. A
+new chain is appended at the end of a trace at stores or memory transfers when
+``-dfsan-track-origins`` is 1. Memory transfers include LLVM memory transfer
+instructions, glibc memcpy and memmove. When ``-dfsan-track-origins`` is 2, a
+new chain is also appended at loads.
+
+Other instructions do not create new chains, but simply propagate origin trace
+IDs. If an instruction has more than one operands with non-zero labels, the origin
+treace ID of the last operand with non-zero label is propagated to the result of
+the instruction.
+
 Memory layout and label management
 --
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106895: [dfsan][NFC] Update API interfaces

2021-07-27 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG00411ebeeb71: [dfsan][NFC] Update API interfaces (authored 
by Jianzhou Zhao jianzho...@google.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106895/new/

https://reviews.llvm.org/D106895

Files:
  clang/docs/DataFlowSanitizerDesign.rst


Index: clang/docs/DataFlowSanitizerDesign.rst
===
--- clang/docs/DataFlowSanitizerDesign.rst
+++ clang/docs/DataFlowSanitizerDesign.rst
@@ -48,12 +48,79 @@
   /// value.
   dfsan_label dfsan_get_label(long data);
 
+  /// Retrieves the label associated with the data at the given address.
+  dfsan_label dfsan_read_label(const void *addr, size_t size);
+
   /// Returns whether the given label label contains the label elem.
   int dfsan_has_label(dfsan_label label, dfsan_label elem);
 
   /// Computes the union of \c l1 and \c l2, resulting in a union label.
   dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2);
 
+  /// Flushes the DFSan shadow, i.e. forgets about all labels currently 
associated
+  /// with the application memory.  Use this call to start over the taint 
tracking
+  /// within the same process.
+  ///
+  /// Note: If another thread is working with tainted data during the flush, 
that
+  /// taint could still be written to shadow after the flush.
+  void dfsan_flush(void);
+
+The following functions are provided to check origin tracking status and 
results.
+
+.. code-block:: c
+
+  /// Retrieves the immediate origin associated with the given data. The 
returned
+  /// origin may point to another origin.
+  ///
+  /// The type of 'data' is arbitrary. The function accepts a value of any 
type,
+  /// which can be truncated or extended (implicitly or explicitly) as 
necessary.
+  /// The truncation/extension operations will preserve the label of the 
original
+  /// value.
+  dfsan_origin dfsan_get_origin(long data);
+
+  /// Retrieves the very first origin associated with the data at the given
+  /// address.
+  dfsan_origin dfsan_get_init_origin(const void *addr);
+
+  /// Prints the origin trace of the label at the address `addr` to stderr. It 
also
+  /// prints description at the beginning of the trace. If origin tracking is 
not
+  /// on, or the address is not labeled, it prints nothing.
+  void dfsan_print_origin_trace(const void *addr, const char *description);
+
+  /// Prints the origin trace of the label at the address `addr` to a 
pre-allocated
+  /// output buffer. If origin tracking is not on, or the address is`
+  /// not labeled, it prints nothing.
+  ///
+  /// `addr` is the tainted memory address whose origin we are printing.
+  /// `description` is a description printed at the beginning of the trace.
+  /// `out_buf` is the output buffer to write the results to. `out_buf_size` is
+  /// the size of `out_buf`. The function returns the number of symbols that
+  /// should have been written to `out_buf` (not including trailing null byte 
'\0').
+  /// Thus, the string is truncated iff return value is not less than 
`out_buf_size`.
+  size_t dfsan_sprint_origin_trace(const void *addr, const char *description,
+   char *out_buf, size_t out_buf_size);
+
+  /// Returns the value of `-dfsan-track-origins`.
+  int dfsan_get_track_origins(void);
+
+The following functions are provided to register hooks called by custom 
wrappers.
+
+.. code-block:: c
+
+  /// Sets a callback to be invoked on calls to `write`.  The callback is 
invoked
+  /// before the write is done. The write is not guaranteed to succeed when the
+  /// callback executes. Pass in NULL to remove any callback.
+  typedef void (*dfsan_write_callback_t)(int fd, const void *buf, size_t 
count);
+  void dfsan_set_write_callback(dfsan_write_callback_t labeled_write_callback);
+
+  /// Callbacks to be invoked on calls to `memcmp` or `strncmp`.
+  void dfsan_weak_hook_memcmp(void *caller_pc, const void *s1, const void *s2,
+  size_t n, dfsan_label s1_label,
+  dfsan_label s2_label, dfsan_label n_label);
+  void dfsan_weak_hook_strncmp(void *caller_pc, const char *s1, const char *s2,
+  size_t n, dfsan_label s1_label,
+  dfsan_label s2_label, dfsan_label n_label);
+
 Taint label representation
 --
 


Index: clang/docs/DataFlowSanitizerDesign.rst
===
--- clang/docs/DataFlowSanitizerDesign.rst
+++ clang/docs/DataFlowSanitizerDesign.rst
@@ -48,12 +48,79 @@
   /// value.
   dfsan_label dfsan_get_label(long data);
 
+  /// Retrieves the label associated with the data at the given address.
+  dfsan_label dfsan_read_label(const void *addr, size_t size);
+
   /// Returns whether the given label label 

[PATCH] D106833: [dfsan][NFC] Add compile flags and environment variables to doc

2021-07-26 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7b7638dfee5: [dfsan][NFC] Add compile flags and environment 
variables to doc (authored by Jianzhou Zhao jianzho...@google.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106833/new/

https://reviews.llvm.org/D106833

Files:
  clang/docs/DataFlowSanitizer.rst


Index: clang/docs/DataFlowSanitizer.rst
===
--- clang/docs/DataFlowSanitizer.rst
+++ clang/docs/DataFlowSanitizer.rst
@@ -137,6 +137,88 @@
   fun:memcpy=uninstrumented
   fun:memcpy=custom
 
+Compilation Flags
+-
+
+* ``-dfsan-abilist`` -- The additional ABI list files that control how shadow
+  parameters are passed. File names are separated by comma.
+* ``-dfsan-combine-pointer-labels-on-load`` -- Controls whether to include or
+  ignore the labels of pointers in load instructions. Its default value is 
true.
+  For example:
+
+.. code-block:: c++
+  v = *p;
+
+If the flag is true, the label of ``v`` is the union of the label of ``p`` and
+the label of ``*p``. If the flag is false, the label of ``v`` is the label of
+just ``*p``.
+* ``-dfsan-combine-pointer-labels-on-store`` -- Controls whether to include or
+  ignore the labels of pointers in store instructions. Its default value is
+  false. For example:
+
+.. code-block:: c++
+  *p = v;
+
+If the flag is true, the label of ``*p`` is the union of the label of ``p`` and
+the label of ``v``. If the flag is false, the label of ``*p`` is the label of
+just ``v``.
+* ``-dfsan-combine-offset-labels-on-gep`` -- Controls whether to propagate
+  labels of offsets in GEP instructions. Its default value is true. For 
example:
+
+.. code-block:: c++
+  p += i;
+
+If the flag is true, the label of ``p`` is the union of the label of ``p`` and
+the label of ``i``. If the flag is false, the label of ``p`` is unchanged.
+* ``-dfsan-track-select-control-flow`` -- Controls whether to track the control
+  flow of select instructions. Its default value is true. For example:
+
+.. code-block:: c++
+  v = b? v1: v2;
+
+If the flag is true, the label of ``v`` is the union of the labels of ``b``,
+``v1`` and ``v2``.  If the flag is false, the label of ``v`` is the union of 
the
+labels of just ``v1`` and ``v2``.
+* ``-dfsan-event-callbacks`` -- An experimental feature that inserts callbacks 
for
+certain data events. Currently callbacks are only inserted for loads, stores,
+memory transfers (i.e. memcpy and memmove), and comparisons. Its default value
+is false. If this flag is set to true, a user must provide definitions for the
+following callback functions:
+
+.. code-block:: c++
+  void __dfsan_load_callback(dfsan_label Label, void* Addr);
+  void __dfsan_store_callback(dfsan_label Label, void* Addr);
+  void __dfsan_mem_transfer_callback(dfsan_label *Start, size_t Len);
+  void __dfsan_cmp_callback(dfsan_label CombinedLabel);
+* ``-dfsan-track-origins`` -- Controls how to track origins. When its value is
+  0, the runtime does not track origins. When its value is 1, the runtime 
tracks
+  origins at memory store operations. When its value is 2, the runtime tracks
+  origins at memory load and store operations. Its default value is 0.
+* ``-dfsan-instrument-with-call-threshold`` -- If a function being instrumented
+   requires more than this number of origin stores, use callbacks instead of
+  inline checks (-1 means never use callbacks). Its default value is 3500.
+
+Environment Variables
+-
+
+* ``warn_unimplemented`` -- Whether to warn on unimplemented functions. Its
+  default value is false.
+* ``strict_data_dependencies`` -- Whether to propagate labels only when there 
is
+  explicit obvious data dependency (e.g., when comparing strings, ignore the 
fact
+  that the output of the comparison might be implicit data-dependent on the
+  content of the strings). This applies only to functions with ``custom`` 
category
+  in ABI list. Its default value is true.
+* ``origin_history_size`` -- The limit of origin chain length. Non-positive 
values
+  mean unlimited. Its default value is 16.
+* ``origin_history_per_stack_limit`` -- The limit of origin node's references 
count.
+  Non-positive values mean unlimited. Its default value is 2.
+* ``store_context_size`` -- The depth limit of origin tracking stack traces. 
Its
+  default value is 20.
+* ``zero_in_malloc`` -- Whether to zero shadow space of new allocated memory. 
Its
+  default value is true.
+* ``zero_in_free`` --- Whether to zero shadow space of deallocated memory. Its
+  default value is true.
+
 Example
 ===
 


Index: clang/docs/DataFlowSanitizer.rst
===
--- clang/docs/DataFlowSanitizer.rst
+++ clang/docs/DataFlowSanitizer.rst
@@ -137,6 +137,88 @@
   fun:memcpy=uninstrumented
   

[PATCH] D120846: [AMDGPU] Add gfx1036 target

2022-03-02 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG840695814ae3: [AMDGPU] Add gfx1036 target (authored by 
Aakanksha paa...@amd.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120846/new/

https://reviews.llvm.org/D120846

Files:
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/CodeGenOpenCL/amdgpu-features.cl
  clang/test/Driver/amdgpu-macros.cl
  clang/test/Driver/amdgpu-mcpu.cl
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/AMDGPUUsage.rst
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Object/ELFObjectFile.cpp
  llvm/lib/ObjectYAML/ELFYAML.cpp
  llvm/lib/Support/TargetParser.cpp
  llvm/lib/Target/AMDGPU/GCNProcessors.td
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
  llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
  llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll
  llvm/test/MC/AMDGPU/gfx1011_dlops.s
  llvm/test/MC/AMDGPU/gfx1030_err.s
  llvm/test/MC/AMDGPU/gfx1030_new.s
  llvm/test/MC/Disassembler/AMDGPU/gfx1011_dasm_dlops.txt
  llvm/test/MC/Disassembler/AMDGPU/gfx1030_dasm_new.txt
  llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
  llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
  llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
  llvm/tools/llvm-readobj/ELFDumper.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/plugins/amdgpu/impl/get_elf_mach_gfx_name.cpp

Index: openmp/libomptarget/plugins/amdgpu/impl/get_elf_mach_gfx_name.cpp
===
--- openmp/libomptarget/plugins/amdgpu/impl/get_elf_mach_gfx_name.cpp
+++ openmp/libomptarget/plugins/amdgpu/impl/get_elf_mach_gfx_name.cpp
@@ -60,6 +60,8 @@
 return "gfx1034";
   case EF_AMDGPU_MACH_AMDGCN_GFX1035:
 return "gfx1035";
+  case EF_AMDGPU_MACH_AMDGCN_GFX1036:
+return "gfx1036";
   default:
 return "--unknown gfx";
   }
Index: openmp/libomptarget/DeviceRTL/CMakeLists.txt
===
--- openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -96,7 +96,7 @@
   endif()
 endforeach()
 
-set(amdgpu_mcpus gfx700 gfx701 gfx801 gfx803 gfx900 gfx902 gfx906 gfx908 gfx90a gfx90c gfx940 gfx1010 gfx1030 gfx1031)
+set(amdgpu_mcpus gfx700 gfx701 gfx801 gfx803 gfx900 gfx902 gfx906 gfx908 gfx90a gfx90c gfx940 gfx1010 gfx1030 gfx1031 gfx1032 gfx1033 gfx1034 gfx1035 gfx1036)
 if (DEFINED LIBOMPTARGET_AMDGCN_GFXLIST)
   set(amdgpu_mcpus ${LIBOMPTARGET_AMDGCN_GFXLIST})
 endif()
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1538,6 +1538,7 @@
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1033),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1034),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1035),
+  LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1036),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_FEATURE_XNACK_V3),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_FEATURE_SRAMECC_V3)
 };
@@ -1593,6 +1594,7 @@
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1033),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1034),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1035),
+  LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1036),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_FEATURE_XNACK_ANY_V4),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_FEATURE_XNACK_OFF_V4),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_FEATURE_XNACK_ON_V4),
Index: llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
===
--- llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
+++ llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
@@ -295,6 +295,15 @@
 # RUN: yaml2obj %s -o %t -DABI_VERSION=2 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1035
 # RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=2 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1035 -DFLAG_VALUE=0x3D
 
+# RUN: yaml2obj %s -o %t -DABI_VERSION=0 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1036
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=0 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1036 -DFLAG_VALUE=0x45
+
+# RUN: yaml2obj %s -o %t -DABI_VERSION=1 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1036
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=1 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1036 

[PATCH] D119837: [RISCV] Fix the include search path order between sysroot and resource folder

2022-02-20 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG079d13668bf1: [RISCV] Fix the include search path order 
between sysroot and resource folder (authored by Kito Cheng 
kito.ch...@sifive.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119837/new/

https://reviews.llvm.org/D119837

Files:
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/test/Driver/Inputs/resource_dir/include/.keep
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain.c


Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -153,6 +153,20 @@
 // C-RV64-RTLIB-COMPILERRT-LP64: "--start-group" "-lc" "-lgloss" "--end-group" 
"{{.*}}libclang_rt.builtins-riscv64.a"
 // C-RV64-RTLIB-COMPILERRT-LP64: "{{.*}}clang_rt.crtend-riscv64.o"
 
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
+// RUN:   -resource-dir=%s/Inputs/resource_dir 2>&1 \
+// RUN:   | FileCheck -check-prefix=RESOURCE-INC %s
+// RESOURCE-INC: "-internal-isystem" "{{.*}}/Inputs/resource_dir/include"
+// RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv64_tree/{{.*}}/riscv64-unknown-elf/include"
+
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
+// RUN:   -resource-dir=%s/Inputs/resource_dir -nobuiltininc 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO-RESOURCE-INC %s
+// NO-RESOURCE-INC-NOT: "-internal-isystem" "{{.*}}Inputs/resource_dir/include"
+// NO-RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv64_tree/{{.*}}/riscv64-unknown-elf/include"
+
 // RUN: %clang -target riscv64 %s -emit-llvm -S -o - | FileCheck %s
 
 typedef __builtin_va_list va_list;
Index: clang/test/Driver/riscv32-toolchain.c
===
--- clang/test/Driver/riscv32-toolchain.c
+++ clang/test/Driver/riscv32-toolchain.c
@@ -197,6 +197,20 @@
 // C-RV32-RTLIB-COMPILERRT-ILP32: "--start-group" "-lc" "-lgloss" 
"--end-group" "{{.*}}libclang_rt.builtins-riscv32.a"
 // C-RV32-RTLIB-COMPILERRT-ILP32: "{{.*}}clang_rt.crtend-riscv32.o"
 
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv32_tree \
+// RUN:   -resource-dir=%s/Inputs/resource_dir 2>&1 \
+// RUN:   | FileCheck -check-prefix=RESOURCE-INC %s
+// RESOURCE-INC: "-internal-isystem" "{{.*}}/Inputs/resource_dir/include"
+// RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv32_tree/{{.*}}/riscv32-unknown-elf/include"
+
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv32_tree \
+// RUN:   -resource-dir=%s/Inputs/resource_dir -nobuiltininc 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO-RESOURCE-INC %s
+// NO-RESOURCE-INC-NOT: "-internal-isystem" 
"{{.*}}/Inputs/resource_dir/include"
+// NO-RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv32_tree/{{.*}}/riscv32-unknown-elf/include"
+
 // RUN: %clang -target riscv32 %s -emit-llvm -S -o - | FileCheck %s
 
 typedef __builtin_va_list va_list;
Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -98,6 +98,12 @@
   if (DriverArgs.hasArg(options::OPT_nostdinc))
 return;
 
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(getDriver().ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
   if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
 SmallString<128> Dir(computeSysRoot());
 llvm::sys::path::append(Dir, "include");


Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -153,6 +153,20 @@
 // C-RV64-RTLIB-COMPILERRT-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "{{.*}}libclang_rt.builtins-riscv64.a"
 // C-RV64-RTLIB-COMPILERRT-LP64: "{{.*}}clang_rt.crtend-riscv64.o"
 
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
+// RUN:   -resource-dir=%s/Inputs/resource_dir 2>&1 \
+// RUN:   | FileCheck -check-prefix=RESOURCE-INC %s
+// RESOURCE-INC: "-internal-isystem" "{{.*}}/Inputs/resource_dir/include"
+// RESOURCE-INC: "-internal-isystem" "{{.*}}/basic_riscv64_tree/{{.*}}/riscv64-unknown-elf/include"
+
+// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
+// RUN:   

[PATCH] D120134: [analyzer] refactor makeIntValWithPtrWidth, remove getZeroWithPtrWidth (NFC)

2022-03-23 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5fdc4dd77704: [analyzer] refactor makeIntValWithPtrWidth, 
remove getZeroWithPtrWidth (NFC) (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120134/new/

https://reviews.llvm.org/D120134

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp


Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -742,9 +742,6 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
-  //and `getIntWithPtrWidth()` functions to prevent future
-  //confusion
   if (!Ty->isReferenceType())
 return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
   CastTy);
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1345,8 +1345,9 @@
 case Stmt::GNUNullExprClass: {
   // GNU __null is a pointer-width integer, not an actual pointer.
   ProgramStateRef state = Pred->getState();
-  state = state->BindExpr(S, Pred->getLocationContext(),
-  svalBuilder.makeIntValWithPtrWidth(0, false));
+  state = state->BindExpr(
+  S, Pred->getLocationContext(),
+  svalBuilder.makeIntValWithWidth(getContext().VoidPtrTy, 0));
   Bldr.generateNode(S, Pred, state);
   break;
 }
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2608,8 +2608,9 @@
 
   // Compare the size argument to 0.
   DefinedOrUnknownSVal SizeZero =
-svalBuilder.evalEQ(State, TotalSize.castAs(),
-   svalBuilder.makeIntValWithPtrWidth(0, false));
+  svalBuilder.evalEQ(State, TotalSize.castAs(),
+ svalBuilder.makeIntValWithWidth(
+ svalBuilder.getContext().getSizeType(), 0));
 
   ProgramStateRef StatePtrIsNull, StatePtrNotNull;
   std::tie(StatePtrIsNull, StatePtrNotNull) = State->assume(PtrEQ);
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -332,9 +332,8 @@
 return nonloc::ConcreteInt(BasicVals.getIntValue(integer, isUnsigned));
   }
 
-  NonLoc makeIntValWithPtrWidth(uint64_t integer, bool isUnsigned) {
-return nonloc::ConcreteInt(
-BasicVals.getIntWithPtrWidth(integer, isUnsigned));
+  NonLoc makeIntValWithWidth(QualType ptrType, uint64_t integer) {
+return nonloc::ConcreteInt(BasicVals.getValue(integer, ptrType));
   }
 
   NonLoc makeLocAsInteger(Loc loc, unsigned bits) {
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -220,14 +220,6 @@
 return getValue(0, Ctx.getTypeSize(T), true);
   }
 
-  const llvm::APSInt (bool isUnsigned = true) {
-return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
-  }
-
-  const llvm::APSInt (uint64_t X, bool isUnsigned) {
-return getValue(X, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
-  }
-
   const llvm::APSInt (bool b, QualType T) {
 return getValue(b ? 1 : 0, Ctx.getIntWidth(T),
 T->isUnsignedIntegerOrEnumerationType());


Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -742,9 +742,6 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: Cleanup 

[PATCH] D122277: [analyzer] Fix crash in RangedConstraintManager.cpp

2022-03-23 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ef7ac51af67: [analyzer] Fix crash in 
RangedConstraintManager.cpp (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122277/new/

https://reviews.llvm.org/D122277

Files:
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/symbol-simplification-bo-div.c

Index: clang/test/Analysis/symbol-simplification-bo-div.c
===
--- /dev/null
+++ clang/test/Analysis/symbol-simplification-bo-div.c
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
+// RUN:-triple x86_64-pc-linux-gnu -verify
+
+// don't crash
+// expected-no-diagnostics
+
+int a, b;
+int c(void) {
+  unsigned d = a;
+  --d;
+  short e = b / b - a;
+  ++e;
+  return d <= 0 && e && e;
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -48,47 +48,48 @@
 
   if (const auto *SSE = dyn_cast(Sym)) {
 BinaryOperator::Opcode Op = SSE->getOpcode();
-assert(BinaryOperator::isComparisonOp(Op));
-
-// We convert equality operations for pointers only.
-if (Loc::isLocType(SSE->getLHS()->getType()) &&
-Loc::isLocType(SSE->getRHS()->getType())) {
-  // Translate "a != b" to "(b - a) != 0".
-  // We invert the order of the operands as a heuristic for how loop
-  // conditions are usually written ("begin != end") as compared to length
-  // calculations ("end - begin"). The more correct thing to do would be to
-  // canonicalize "a - b" and "b - a", which would allow us to treat
-  // "a != b" and "b != a" the same.
-
-  SymbolManager  = getSymbolManager();
-  QualType DiffTy = SymMgr.getContext().getPointerDiffType();
-  SymbolRef Subtraction =
-  SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
-
-  const llvm::APSInt  = getBasicVals().getValue(0, DiffTy);
-  Op = BinaryOperator::reverseComparisonOp(Op);
-  if (!Assumption)
-Op = BinaryOperator::negateComparisonOp(Op);
-  return assumeSymRel(State, Subtraction, Op, Zero);
-}
+if (BinaryOperator::isComparisonOp(Op)) {
+
+  // We convert equality operations for pointers only.
+  if (Loc::isLocType(SSE->getLHS()->getType()) &&
+  Loc::isLocType(SSE->getRHS()->getType())) {
+// Translate "a != b" to "(b - a) != 0".
+// We invert the order of the operands as a heuristic for how loop
+// conditions are usually written ("begin != end") as compared to length
+// calculations ("end - begin"). The more correct thing to do would be
+// to canonicalize "a - b" and "b - a", which would allow us to treat
+// "a != b" and "b != a" the same.
+
+SymbolManager  = getSymbolManager();
+QualType DiffTy = SymMgr.getContext().getPointerDiffType();
+SymbolRef Subtraction =
+SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
+
+const llvm::APSInt  = getBasicVals().getValue(0, DiffTy);
+Op = BinaryOperator::reverseComparisonOp(Op);
+if (!Assumption)
+  Op = BinaryOperator::negateComparisonOp(Op);
+return assumeSymRel(State, Subtraction, Op, Zero);
+  }
 
-if (BinaryOperator::isEqualityOp(Op)) {
-  SymbolManager  = getSymbolManager();
+  if (BinaryOperator::isEqualityOp(Op)) {
+SymbolManager  = getSymbolManager();
 
-  QualType ExprType = SSE->getType();
-  SymbolRef CanonicalEquality =
-  SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
+QualType ExprType = SSE->getType();
+SymbolRef CanonicalEquality =
+SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
 
-  bool WasEqual = SSE->getOpcode() == BO_EQ;
-  bool IsExpectedEqual = WasEqual == Assumption;
+bool WasEqual = SSE->getOpcode() == BO_EQ;
+bool IsExpectedEqual = WasEqual == Assumption;
 
-  const llvm::APSInt  = getBasicVals().getValue(0, ExprType);
+const llvm::APSInt  = getBasicVals().getValue(0, ExprType);
 
-  if (IsExpectedEqual) {
-return assumeSymNE(State, CanonicalEquality, Zero, Zero);
-  }
+if (IsExpectedEqual) {
+  return assumeSymNE(State, CanonicalEquality, Zero, Zero);
+}
 
-  return assumeSymEQ(State, CanonicalEquality, Zero, Zero);
+return assumeSymEQ(State, CanonicalEquality, Zero, Zero);
+  }
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122513: [analyzer] Fix "RhsLoc and LhsLoc bitwidth must be same"

2022-03-29 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfe8b2236ef9c: [analyzer] Fix RhsLoc and LhsLoc 
bitwidth must be same (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122513/new/

https://reviews.llvm.org/D122513

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/addrspace-null.c


Index: clang/test/Analysis/addrspace-null.c
===
--- /dev/null
+++ clang/test/Analysis/addrspace-null.c
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DAMDGCN_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+//
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DDEFAULT_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+
+// expected-no-diagnostics
+
+#define DEVICE __attribute__((address_space(3)))
+
+#if defined(AMDGCN_TRIPLE)
+// this crashes
+int fn1() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (void *)0;
+}
+
+// does not crash
+int fn2() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+
+// this crashes
+int fn3() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+#endif
+
+// does not crash
+int fn4() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (void *)0;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -682,8 +682,11 @@
   }
 
   // Pointer to any pointer.
-  if (Loc::isLocType(CastTy))
-return V;
+  if (Loc::isLocType(CastTy)) {
+llvm::APSInt Value = V.getValue();
+BasicVals.getAPSIntType(CastTy).apply(Value);
+return loc::ConcreteInt(BasicVals.getValue(Value));
+  }
 
   // Pointer to whatever else.
   return UnknownVal();


Index: clang/test/Analysis/addrspace-null.c
===
--- /dev/null
+++ clang/test/Analysis/addrspace-null.c
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DAMDGCN_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+//
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core -DDEFAULT_TRIPLE \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -Wno-implicit-int -Wno-int-conversion -verify %s
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+
+// expected-no-diagnostics
+
+#define DEVICE __attribute__((address_space(3)))
+
+#if defined(AMDGCN_TRIPLE)
+// this crashes
+int fn1() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (void *)0;
+}
+
+// does not crash
+int fn2() {
+  int val = 0;
+  DEVICE int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+
+// this crashes
+int fn3() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (DEVICE void *)0;
+}
+#endif
+
+// does not crash
+int fn4() {
+  int val = 0;
+  int *dptr = val;
+  return dptr == (void *)0;
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -682,8 +682,11 @@
   }
 
   // Pointer to any pointer.
-  if (Loc::isLocType(CastTy))
-return V;
+  if (Loc::isLocType(CastTy)) {
+llvm::APSInt Value = V.getValue();
+BasicVals.getAPSIntType(CastTy).apply(Value);
+return loc::ConcreteInt(BasicVals.getValue(Value));
+  }
 
   // Pointer to whatever else.
   return UnknownVal();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118050: [analyzer] Avoid checking addrspace pointers in cstring checker

2022-03-31 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d5b824e3df2: [analyzer] Avoid checking addrspace pointers 
in cstring checker (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118050/new/

https://reviews.llvm.org/D118050

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/cstring-addrspace.c

Index: clang/test/Analysis/cstring-addrspace.c
===
--- /dev/null
+++ clang/test/Analysis/cstring-addrspace.c
@@ -0,0 +1,64 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
+// RUN: -analyze -analyzer-checker=core,alpha.unix.cstring \
+// RUN: -analyze -analyzer-checker=debug.ExprInspection \
+// RUN: -analyzer-config crosscheck-with-z3=true -verify %s \
+// RUN: -Wno-incompatible-library-redeclaration
+// REQUIRES: z3
+
+void clang_analyzer_warnIfReached();
+
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+#define DEVICE __attribute__((address_space(3)))
+_Static_assert(sizeof(int *) == 8, "");
+_Static_assert(sizeof(DEVICE int *) == 4, "");
+_Static_assert(sizeof(void *) == 8, "");
+_Static_assert(sizeof(DEVICE void *) == 4, "");
+
+// Copy from host to device memory. Note this is specialized
+// since one of the parameters is assigned an address space such
+// that the sizeof the the pointer is different than the other.
+//
+// Some downstream implementations may have specialized memcpy
+// routines that copy from one address space to another. In cases
+// like that, the address spaces are assumed to not overlap, so the
+// cstring overlap check is not needed. When a static analysis report
+// is generated in as case like this, SMTConv may attempt to create
+// a refutation to Z3 with different bitwidth pointers which lead to
+// a crash. This is not common in directly used upstream compiler builds,
+// but can be seen in specialized downstrean implementations. This case
+// covers those specific instances found and debugged.
+//
+// Since memcpy is a builtin, a specialized builtin instance named like
+// 'memcpy_special' will hit in cstring, triggering this behavior. The
+// best we can do for an upstream test is use the same memcpy function name.
+DEVICE void *memcpy(DEVICE void *dst, const void *src, unsigned long len);
+
+void top1(DEVICE void *dst, void *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top2(DEVICE int *dst, void *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top3(DEVICE int *dst, int *src, int len) {
+  memcpy(dst, src, len);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void top4() {
+  memcpy((DEVICE void *)1, (const void *)1, 1);
+
+  // Create a bugreport for triggering Z3 refutation.
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -715,11 +715,41 @@
   llvm_unreachable("Fields not found in parent record's definition");
 }
 
+// This is used in debug builds only for now because some downstream users
+// may hit this assert in their subsequent merges.
+// There are still places in the analyzer where equal bitwidth Locs
+// are compared, and need to be found and corrected. Recent previous fixes have
+// addressed the known problems of making NULLs with specific bitwidths
+// for Loc comparisons along with deprecation of APIs for the same purpose.
+//
+static void assertEqualBitWidths(ProgramStateRef State, Loc RhsLoc,
+ Loc LhsLoc) {
+  // Implements a "best effort" check for RhsLoc and LhsLoc bit widths
+  ASTContext  = State->getStateManager().getContext();
+  uint64_t RhsBitwidth =
+  RhsLoc.getType(Ctx).isNull() ? 0 : Ctx.getTypeSize(RhsLoc.getType(Ctx));
+  uint64_t LhsBitwidth =
+  LhsLoc.getType(Ctx).isNull() ? 0 : Ctx.getTypeSize(LhsLoc.getType(Ctx));
+  if (RhsBitwidth && LhsBitwidth &&
+  (LhsLoc.getSubKind() == RhsLoc.getSubKind())) {
+assert(RhsBitwidth == LhsBitwidth &&
+   "RhsLoc and LhsLoc bitwidth must be same!");
+  }
+}
+
 // FIXME: all this logic will change if/when we have MemRegion::getLocation().
 SVal 

[PATCH] D119601: [analyzer] Refactor makeNull to makeNullWithWidth (NFC)

2022-03-22 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG985888411da9: [analyzer] Refactor makeNull to 
makeNullWithWidth (NFC) (authored by vabridgers, committed by einvbri 
vince.a.bridg...@ericsson.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119601/new/

https://reviews.llvm.org/D119601

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/cast-value-notes.cpp

Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -1,9 +1,22 @@
 // RUN: %clang_analyze_cc1 -std=c++14 \
 // RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
-// RUN:  -analyzer-output=text -verify %s
+// RUN:  -analyzer-output=text -verify -DDEFAULT_TRIPLE %s 2>&1 | FileCheck %s -check-prefix=DEFAULT-CHECK
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-output=text -verify -DAMDGCN_TRIPLE %s 2>&1 | FileCheck %s -check-prefix=AMDGCN-CHECK
 
 #include "Inputs/llvm.h"
 
+// The amggcn triple case uses an intentionally different address space.
+// The core.NullDereference checker intentionally ignores checks
+// that use address spaces, so the case is differentiated here.
+//
+// From https://llvm.org/docs/AMDGPUUsage.html#address-spaces,
+// select address space 3 (local), since the pointer size is
+// different than Generic.
+#define DEVICE __attribute__((address_space(3)))
+
 namespace clang {
 struct Shape {
   template 
@@ -21,12 +34,30 @@
 using namespace llvm;
 using namespace clang;
 
+void clang_analyzer_printState();
+
+#if defined(DEFAULT_TRIPLE)
 void evalReferences(const Shape ) {
   const auto  = dyn_cast(S);
   // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
   // expected-note@-2 {{Dereference of null pointer}}
   // expected-warning@-3 {{Dereference of null pointer}}
+  clang_analyzer_printState();
+  // DEFAULT-CHECK: "dynamic_types": [
+  // DEFAULT-CHECK-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const class clang::Circle &", "sub_classable": true }
+  (void)C;
+}
+#elif defined(AMDGCN_TRIPLE)
+void evalReferences(const Shape ) {
+  const auto  = dyn_cast(S);
+  clang_analyzer_printState();
+  // AMDGCN-CHECK: "dynamic_types": [
+  // AMDGCN-CHECK-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const __attribute__((address_space(3))) class clang::Circle &", "sub_classable": true }
+  (void)C;
 }
+#else
+#error Target must be specified, and must be pinned
+#endif
 
 void evalNonNullParamNonNullReturnReference(const Shape ) {
   const auto *C = dyn_cast_or_null(S);
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -61,7 +61,7 @@
 
 DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType type) {
   if (Loc::isLocType(type))
-return makeNull();
+return makeNullWithType(type);
 
   if (type->isIntegralOrEnumerationType())
 return makeIntVal(0, type);
@@ -359,7 +359,7 @@
 return makeBoolVal(cast(E));
 
   case Stmt::CXXNullPtrLiteralExprClass:
-return makeNull();
+return makeNullWithType(E->getType());
 
   case Stmt::CStyleCastExprClass:
   case Stmt::CXXFunctionalCastExprClass:
@@ -399,7 +399,7 @@
 
 if (Loc::isLocType(E->getType()))
   if (E->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull))
-return makeNull();
+return makeNullWithType(E->getType());
 
 return None;
   }
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2410,7 +2410,7 @@
   SVal V;
 
   if (Loc::isLocType(T))
-V = svalBuilder.makeNull();
+V = svalBuilder.makeNullWithType(T);
   else if (T->isIntegralOrEnumerationType())
 V = svalBuilder.makeZeroVal(T);
   else if (T->isStructureOrClassType() || T->isArrayType()) {
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -460,7 +460,8 

[PATCH] D119440: [OpenMP][NFC] update status for 5.1 'nothing' directive to 'worked on'

2022-02-10 Thread Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG02a05097e700: [OpenMP][NFC] update status for 5.1 
nothing directive to worked on (authored by dreachem, 
committed by Chi-Chun, Chen chichunchen...@gmail.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119440/new/

https://reviews.llvm.org/D119440

Files:
  clang/docs/OpenMPSupport.rst


Index: clang/docs/OpenMPSupport.rst
===
--- clang/docs/OpenMPSupport.rst
+++ clang/docs/OpenMPSupport.rst
@@ -339,7 +339,7 @@
 
+--+--+--+---+
 | misc extension   | assume and assumes directives 
   | :part:`worked on`| 
  |
 
+--+--+--+---+
-| misc extension   | nothing directive 
   | :none:`unclaimed`| 
  |
+| misc extension   | nothing directive 
   | :part:`worked on`| 
  |
 
+--+--+--+---+
 | misc extension   | masked construct and related combined 
constructs | :part:`worked on`| D5, D100514 
  |
 
+--+--+--+---+


Index: clang/docs/OpenMPSupport.rst
===
--- clang/docs/OpenMPSupport.rst
+++ clang/docs/OpenMPSupport.rst
@@ -339,7 +339,7 @@
 +--+--+--+---+
 | misc extension   | assume and assumes directives| :part:`worked on`|   |
 +--+--+--+---+
-| misc extension   | nothing directive| :none:`unclaimed`|   |
+| misc extension   | nothing directive| :part:`worked on`|   |
 +--+--+--+---+
 | misc extension   | masked construct and related combined constructs | :part:`worked on`| D5, D100514   |
 +--+--+--+---+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D117972: [PowerPC] Fix SSE translation on FreeBSD

2022-02-05 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2f4080c10f4: [PowerPC] Fix SSE translation on FreeBSD 
(authored by pkubaj, committed by Qiu Chaofan q...@ecnelises.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117972/new/

https://reviews.llvm.org/D117972

Files:
  clang/lib/Headers/ppc_wrappers/mm_malloc.h


Index: clang/lib/Headers/ppc_wrappers/mm_malloc.h
===
--- clang/lib/Headers/ppc_wrappers/mm_malloc.h
+++ clang/lib/Headers/ppc_wrappers/mm_malloc.h
@@ -19,7 +19,7 @@
 #ifndef __cplusplus
 extern int posix_memalign (void **, size_t, size_t);
 #else
-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+extern "C" int posix_memalign (void **, size_t, size_t);
 #endif
 
 static __inline void *


Index: clang/lib/Headers/ppc_wrappers/mm_malloc.h
===
--- clang/lib/Headers/ppc_wrappers/mm_malloc.h
+++ clang/lib/Headers/ppc_wrappers/mm_malloc.h
@@ -19,7 +19,7 @@
 #ifndef __cplusplus
 extern int posix_memalign (void **, size_t, size_t);
 #else
-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+extern "C" int posix_memalign (void **, size_t, size_t);
 #endif
 
 static __inline void *
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159163: [analyzer][NFC] Workaround miscompilation on recent MSVC

2023-08-30 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b3f41c55d92: [analyzer][NFC] Workaround miscompilation on 
recent MSVC (authored by dingfei fd...@feysh.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159163/new/

https://reviews.llvm.org/D159163

Files:
  clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -91,7 +91,7 @@
 
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDual(ProgramStateRef State, DefinedSVal Cond) {
-  auto AssumeFun = [&](bool Assumption) {
+  auto AssumeFun = [&, Cond](bool Assumption) {
 return assumeInternal(State, Cond, Assumption);
   };
   return assumeDualImpl(State, AssumeFun);


Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -91,7 +91,7 @@
 
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDual(ProgramStateRef State, DefinedSVal Cond) {
-  auto AssumeFun = [&](bool Assumption) {
+  auto AssumeFun = [&, Cond](bool Assumption) {
 return assumeInternal(State, Cond, Assumption);
   };
   return assumeDualImpl(State, AssumeFun);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158948: [clang][ASTImporter] Add import of type-related nodes

2023-08-31 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7bd43675753: [clang][ASTImporter] Add import of a few type 
related nodes (authored by dingfei fd...@feysh.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158948/new/

https://reviews.llvm.org/D158948

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterObjCTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -583,6 +583,96 @@
   functionDecl(hasDescendant(typedefDecl(has(atomicType());
 }
 
+TEST_P(ImportType, ImportBitIntType) {
+  const AstTypeMatcher bitIntType;
+  MatchVerifier Verifier;
+  testImport("_BitInt(10) declToImport;", Lang_CXX11, "", Lang_CXX11, Verifier,
+ varDecl(hasType(bitIntType(;
+}
+
+TEST_P(ImportType, ImportDependentBitIntType) {
+  const AstTypeMatcher dependentBitIntType;
+  MatchVerifier Verifier;
+  testImport("template using declToImport = _BitInt(Width);",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typeAliasTemplateDecl(
+ has(typeAliasDecl(hasType(dependentBitIntType());
+}
+
+TEST_P(ImportType, ImportDependentAddressSpaceType) {
+  const AstTypeMatcher dependentAddressSpaceType;
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((address_space(AddrSpace)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentAddressSpaceType());
+}
+
+TEST_P(ImportType, ImportVectorType) {
+  const AstTypeMatcher vectorType;
+  MatchVerifier Verifier;
+  testImport("typedef int __attribute__((vector_size(12))) declToImport;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typedefDecl(hasType(vectorType(;
+}
+
+TEST_P(ImportType, ImportDependentVectorType) {
+  const AstTypeMatcher dependentVectorType;
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((vector_size(Size)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentVectorType());
+}
+
+struct ImportOpenCLPipe : ImportType {
+  std::vector getExtraArgs() const override {
+return {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"};
+  }
+};
+
+TEST_P(ImportOpenCLPipe, ImportPipeType) {
+  const AstTypeMatcher pipeType;
+  MatchVerifier Verifier;
+  testImport("typedef pipe int declToImport;", Lang_OpenCL, "", Lang_OpenCL,
+ Verifier, typedefDecl(hasType(pipeType(;
+}
+
+struct ImportMatrixType : ImportType {
+  std::vector getExtraArgs() const override {
+return {"-fenable-matrix"};
+  }
+};
+
+TEST_P(ImportMatrixType, ImportConstantMatrixType) {
+  const AstTypeMatcher constantMatrixType;
+  MatchVerifier Verifier;
+  testImport("typedef int __attribute__((matrix_type(5, 5))) declToImport;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typedefDecl(hasType(constantMatrixType(;
+}
+
+TEST_P(ImportMatrixType, ImportDependentSizedMatrixType) {
+  const AstTypeMatcher dependentSizedMatrixType;
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((matrix_type(Rows, Cols)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentSizedMatrixType());
+}
+
 TEST_P(ImportType, ImportUsingType) {
   MatchVerifier Verifier;
   testImport("struct C {};"
Index: clang/unittests/AST/ASTImporterObjCTest.cpp
===
--- clang/unittests/AST/ASTImporterObjCTest.cpp
+++ clang/unittests/AST/ASTImporterObjCTest.cpp
@@ -77,6 +77,22 @@
   }
 }
 
+TEST_P(ImportObjCDecl, ImportObjCTypeParamDecl) {
+  Decl *FromTU = getTuDecl(
+  R"(
+@interface X 
+@end
+  )",
+  Lang_OBJCXX, "input.mm");
+  auto *FromInterfaceDecl = FirstDeclMatcher().match(
+  FromTU, namedDecl(hasName("X")));
+  auto *FromTypeParamDecl =
+  FromInterfaceDecl->getTypeParamListAsWritten()->front();
+
+  auto *ToTypeParamDeclImported = Import(FromTypeParamDecl, Lang_OBJCXX);
+  ASSERT_TRUE(ToTypeParamDeclImported);
+}
+
 static const auto ObjCTestArrayForRunOptions =
 std::array, 2>{
 {std::vector{"-fno-objc-arc"},
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -368,58 +368,9 @@
 
 // Importing types
 ExpectedType VisitType(const Type *T);
-ExpectedType 

[PATCH] D129818: AMDGPU: Make default AMDHSA Code Object Version to be 5

2023-09-12 Thread Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a8d17e79b02: [AMDGPU] Make default AMDHSA Code Object 
Version to be 5 (#65410) (authored by saiislam, committed by GitHub 
nore...@github.com).
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
Herald added projects: clang, OpenMP.
Herald added subscribers: openmp-commits, cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D129818?vs=530947=556533#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129818/new/

https://reviews.llvm.org/D129818

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGenCUDA/amdgpu-code-object-version.cu
  clang/test/CodeGenCUDA/amdgpu-workgroup-size.cu
  clang/test/CodeGenHIP/default-attributes.hip
  clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn.cl
  clang/test/Driver/hip-device-libs.hip
  lld/test/ELF/emulation-amdgpu.s
  lld/test/ELF/lto/amdgcn-oses.ll
  llvm/docs/AMDGPUUsage.rst
  llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
  llvm/test/CodeGen/AMDGPU/GlobalISel/crash-stack-address-O0.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/dropped_debug_info_assert.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-assert-align.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-atomicrmw.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-abi-attribute-hints.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-implicit-args.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-return-values.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-sret.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constant-fold-vector-op.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-indirect-call.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-inline-asm.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-sibling-call.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-tail-call.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-addrspacecast.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.is.private.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.is.shared.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/non-entry-alloca.ll
  llvm/test/CodeGen/AMDGPU/abi-attribute-hints-undefined-behavior.ll
  llvm/test/CodeGen/AMDGPU/addrspacecast-constantexpr.ll
  llvm/test/CodeGen/AMDGPU/addrspacecast.gfx6.ll
  llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-pow-codegen.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa-call.ll
  llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa.ll
  llvm/test/CodeGen/AMDGPU/attributor-noopt.ll
  llvm/test/CodeGen/AMDGPU/blender-no-live-segment-at-def-implicit-def.ll
  llvm/test/CodeGen/AMDGPU/branch-folding-implicit-def-subreg.ll
  llvm/test/CodeGen/AMDGPU/call-alias-register-usage-agpr.ll
  llvm/test/CodeGen/AMDGPU/call-alias-register-usage0.ll
  llvm/test/CodeGen/AMDGPU/call-alias-register-usage1.ll
  llvm/test/CodeGen/AMDGPU/call-alias-register-usage2.ll
  llvm/test/CodeGen/AMDGPU/call-alias-register-usage3.ll
  llvm/test/CodeGen/AMDGPU/call-argument-types.ll
  llvm/test/CodeGen/AMDGPU/call-waitcnt.ll
  llvm/test/CodeGen/AMDGPU/callee-special-input-sgprs-fixed-abi.ll
  llvm/test/CodeGen/AMDGPU/cc-update.ll
  llvm/test/CodeGen/AMDGPU/cf-loop-on-constant.ll
  llvm/test/CodeGen/AMDGPU/codegen-internal-only-func.ll
  llvm/test/CodeGen/AMDGPU/collapse-endcf.ll
  llvm/test/CodeGen/AMDGPU/cross-block-use-is-not-abi-copy.ll
  llvm/test/CodeGen/AMDGPU/cvt_f32_ubyte.ll
  llvm/test/CodeGen/AMDGPU/dagcombine-lshr-and-cmp.ll
  llvm/test/CodeGen/AMDGPU/ds_read2.ll
  llvm/test/CodeGen/AMDGPU/dwarf-multi-register-use-crash.ll
  llvm/test/CodeGen/AMDGPU/elf-header-osabi.ll
  llvm/test/CodeGen/AMDGPU/flat-scratch-init.ll
  llvm/test/CodeGen/AMDGPU/fneg-fabs.ll
  llvm/test/CodeGen/AMDGPU/gfx11-user-sgpr-init16-bug.ll
  llvm/test/CodeGen/AMDGPU/global_atomics_scan_fadd.ll
  llvm/test/CodeGen/AMDGPU/global_atomics_scan_fmax.ll
  llvm/test/CodeGen/AMDGPU/global_atomics_scan_fmin.ll
  llvm/test/CodeGen/AMDGPU/global_atomics_scan_fsub.ll
  llvm/test/CodeGen/AMDGPU/indirect-addressing-term.ll
  llvm/test/CodeGen/AMDGPU/insert-delay-alu-bug.ll
  llvm/test/CodeGen/AMDGPU/kernel-vgpr-spill-mubuf-with-voffset.ll
  llvm/test/CodeGen/AMDGPU/lds-frame-extern.ll
  llvm/test/CodeGen/AMDGPU/lds-global-non-entry-func.ll
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.is.private.ll
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.is.shared.ll
  llvm/test/CodeGen/AMDGPU/llvm.dbg.value.ll
  llvm/test/CodeGen/AMDGPU/lower-kernargs.ll
  llvm/test/CodeGen/AMDGPU/lower-module-lds-via-hybrid.ll
  llvm/test/CodeGen/AMDGPU/lower-module-lds-via-table.ll
  llvm/test/CodeGen/AMDGPU/module-lds-false-sharing.ll

[PATCH] D158953: [analyzer] MmapWriteExecChecker: use getAs instead of castAs

2023-08-29 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2b6160ea3f9a: [analyzer] MmapWriteExecChecker: use getAs 
instead of castAs (authored by dingfei fd...@feysh.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158953/new/

https://reviews.llvm.org/D158953

Files:
  clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
  clang/test/Analysis/mmap-writeexec.c


Index: clang/test/Analysis/mmap-writeexec.c
===
--- clang/test/Analysis/mmap-writeexec.c
+++ clang/test/Analysis/mmap-writeexec.c
@@ -42,3 +42,9 @@
   int m = mprotect(p, 1024, PROT_WRITE | PROT_EXEC); // expected-warning{{Both 
PROT_WRITE and PROT_EXEC flags are set. This can lead to exploitable memory 
regions, which could be overwritten with malicious code}}
   (void)m;
 }
+
+// gh62285: no crash on non concrete arg 'prot'
+void *gh62285(void *addr, int prot)
+{
+  return mmap(addr, 1, prot, 1, 1, 1);
+}
Index: clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -48,8 +48,10 @@
  CheckerContext ) const {
   if (matchesAny(Call, MmapFn, MprotectFn)) {
 SVal ProtVal = Call.getArgSVal(2);
-auto ProtLoc = ProtVal.castAs();
-int64_t Prot = ProtLoc.getValue().getSExtValue();
+auto ProtLoc = ProtVal.getAs();
+if (!ProtLoc)
+  return;
+int64_t Prot = ProtLoc->getValue().getSExtValue();
 if (ProtExecOv != ProtExec)
   ProtExec = ProtExecOv;
 if (ProtReadOv != ProtRead)


Index: clang/test/Analysis/mmap-writeexec.c
===
--- clang/test/Analysis/mmap-writeexec.c
+++ clang/test/Analysis/mmap-writeexec.c
@@ -42,3 +42,9 @@
   int m = mprotect(p, 1024, PROT_WRITE | PROT_EXEC); // expected-warning{{Both PROT_WRITE and PROT_EXEC flags are set. This can lead to exploitable memory regions, which could be overwritten with malicious code}}
   (void)m;
 }
+
+// gh62285: no crash on non concrete arg 'prot'
+void *gh62285(void *addr, int prot)
+{
+  return mmap(addr, 1, prot, 1, 1, 1);
+}
Index: clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -48,8 +48,10 @@
  CheckerContext ) const {
   if (matchesAny(Call, MmapFn, MprotectFn)) {
 SVal ProtVal = Call.getArgSVal(2);
-auto ProtLoc = ProtVal.castAs();
-int64_t Prot = ProtLoc.getValue().getSExtValue();
+auto ProtLoc = ProtVal.getAs();
+if (!ProtLoc)
+  return;
+int64_t Prot = ProtLoc->getValue().getSExtValue();
 if (ProtExecOv != ProtExec)
   ProtExec = ProtExecOv;
 if (ProtReadOv != ProtRead)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


<    1   2   3   4   5   6   7   8   9   10   >