Skip to content

Commit

Permalink
Selectively enable the 64-to-32 bit truncation diagnostic (facebook#802)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#802

Ensures the  GCC diagnostic ignored "-Wshorten-64-to-32" is only
enabled if the C++ compiler supports it.

Reviewed By: fbmal7

Differential Revision: D39100412

fbshipit-source-id: a61b056326633e8ea067bf5b5e547ff89a31fec8
  • Loading branch information
jpporto authored and facebook-github-bot committed Aug 30, 2022
1 parent 1814759 commit 8a6a977
Show file tree
Hide file tree
Showing 85 changed files with 382 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,13 @@ if (HERMES_MEMORY_INSTRUMENTATION)
add_definitions(-DHERMES_MEMORY_INSTRUMENTATION)
endif()

# Disables the GCC 64-to-32 bit truncation diagnostic if the compiler supports
# -Wshorten-64-to-32.
check_cxx_compiler_flag("-Wshorten-64-to-32" CXX_SUPPORTS_SHORTEN_64_TO_32)
if (${CXX_SUPPORTS_SHORTEN_64_TO_32})
add_definitions(-DHERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32)
endif()

set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++17")

# JSI_DIR has always priority over other folders.
Expand Down
3 changes: 3 additions & 0 deletions external/llvh/include/llvh/ADT/APInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
#include <string>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace llvh {
class FoldingSetNodeID;
Expand Down
3 changes: 3 additions & 0 deletions external/llvh/include/llvh/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
#include <utility>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace llvh {

Expand Down
3 changes: 3 additions & 0 deletions external/llvh/include/llvh/ADT/DenseMapInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
#include <utility>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace llvh {

Expand Down
3 changes: 3 additions & 0 deletions external/llvh/include/llvh/ADT/Hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
#include <utility>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace llvh {

Expand Down
3 changes: 3 additions & 0 deletions external/llvh/include/llvh/ADT/MapVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
#include <vector>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace llvh {

Expand Down
3 changes: 3 additions & 0 deletions external/llvh/include/llvh/ADT/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
#include <utility>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace llvh {

Expand Down
3 changes: 3 additions & 0 deletions external/llvh/include/llvh/ADT/StringRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
#include <utility>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace llvh {

Expand Down
3 changes: 3 additions & 0 deletions external/llvh/include/llvh/IR/InstrTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
#include <vector>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace llvh {

Expand Down
3 changes: 3 additions & 0 deletions external/llvh/include/llvh/Support/MathExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
#include <type_traits>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

#ifdef __ANDROID_NDK__
#include <android/api-level.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
diff --git a/xplat/hermes/external/llvh/include/llvh/ADT/APInt.h b/xplat/hermes/external/llvh/include/llvh/ADT/APInt.h
--- a/xplat/hermes/external/llvh/include/llvh/ADT/APInt.h
+++ b/xplat/hermes/external/llvh/include/llvh/ADT/APInt.h
@@ -23,7 +23,10 @@
#include <string>

#pragma GCC diagnostic push
+
+#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
+#endif

namespace llvh {
class FoldingSetNodeID;
diff --git a/xplat/hermes/external/llvh/include/llvh/ADT/DenseMap.h b/xplat/hermes/external/llvh/include/llvh/ADT/DenseMap.h
--- a/xplat/hermes/external/llvh/include/llvh/ADT/DenseMap.h
+++ b/xplat/hermes/external/llvh/include/llvh/ADT/DenseMap.h
@@ -31,7 +31,10 @@
#include <utility>

#pragma GCC diagnostic push
+
+#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
+#endif

namespace llvh {

diff --git a/xplat/hermes/external/llvh/include/llvh/ADT/DenseMapInfo.h b/xplat/hermes/external/llvh/include/llvh/ADT/DenseMapInfo.h
--- a/xplat/hermes/external/llvh/include/llvh/ADT/DenseMapInfo.h
+++ b/xplat/hermes/external/llvh/include/llvh/ADT/DenseMapInfo.h
@@ -24,7 +24,10 @@
#include <utility>

#pragma GCC diagnostic push
+
+#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
+#endif

namespace llvh {

diff --git a/xplat/hermes/external/llvh/include/llvh/ADT/Hashing.h b/xplat/hermes/external/llvh/include/llvh/ADT/Hashing.h
--- a/xplat/hermes/external/llvh/include/llvh/ADT/Hashing.h
+++ b/xplat/hermes/external/llvh/include/llvh/ADT/Hashing.h
@@ -55,7 +55,10 @@
#include <utility>

#pragma GCC diagnostic push
+
+#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
+#endif

namespace llvh {

diff --git a/xplat/hermes/external/llvh/include/llvh/ADT/MapVector.h b/xplat/hermes/external/llvh/include/llvh/ADT/MapVector.h
--- a/xplat/hermes/external/llvh/include/llvh/ADT/MapVector.h
+++ b/xplat/hermes/external/llvh/include/llvh/ADT/MapVector.h
@@ -27,7 +27,10 @@
#include <vector>

#pragma GCC diagnostic push
+
+#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
+#endif

namespace llvh {

diff --git a/xplat/hermes/external/llvh/include/llvh/ADT/SmallVector.h b/xplat/hermes/external/llvh/include/llvh/ADT/SmallVector.h
--- a/xplat/hermes/external/llvh/include/llvh/ADT/SmallVector.h
+++ b/xplat/hermes/external/llvh/include/llvh/ADT/SmallVector.h
@@ -34,7 +34,10 @@
#include <utility>

#pragma GCC diagnostic push
+
+#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
+#endif

namespace llvh {

diff --git a/xplat/hermes/external/llvh/include/llvh/ADT/StringRef.h b/xplat/hermes/external/llvh/include/llvh/ADT/StringRef.h
--- a/xplat/hermes/external/llvh/include/llvh/ADT/StringRef.h
+++ b/xplat/hermes/external/llvh/include/llvh/ADT/StringRef.h
@@ -22,7 +22,10 @@
#include <utility>

#pragma GCC diagnostic push
+
+#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
+#endif

namespace llvh {

diff --git a/xplat/hermes/external/llvh/include/llvh/IR/InstrTypes.h b/xplat/hermes/external/llvh/include/llvh/IR/InstrTypes.h
--- a/xplat/hermes/external/llvh/include/llvh/IR/InstrTypes.h
+++ b/xplat/hermes/external/llvh/include/llvh/IR/InstrTypes.h
@@ -43,7 +43,10 @@
#include <vector>

#pragma GCC diagnostic push
+
+#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
+#endif

namespace llvh {

diff --git a/xplat/hermes/external/llvh/include/llvh/Support/MathExtras.h b/xplat/hermes/external/llvh/include/llvh/Support/MathExtras.h
--- a/xplat/hermes/external/llvh/include/llvh/Support/MathExtras.h
+++ b/xplat/hermes/external/llvh/include/llvh/Support/MathExtras.h
@@ -24,7 +24,10 @@
#include <type_traits>

#pragma GCC diagnostic push
+
+#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
+#endif

#ifdef __ANDROID_NDK__
#include <android/api-level.h>
3 changes: 3 additions & 0 deletions include/hermes/ADT/BitArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#include <bitset>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace hermes {

Expand Down
3 changes: 3 additions & 0 deletions include/hermes/ADT/CompactArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#include <cassert>
#include <limits>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {

namespace vm {
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/ADT/SafeInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include <cstdint>
#include <limits>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {

/// To avoid overflow, we introduce the SafeUInt32 which can be used
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/BCGen/HBC/Bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

#include <memory>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {
class SourceMapGenerator;

Expand Down
3 changes: 3 additions & 0 deletions include/hermes/BCGen/HBC/BytecodeDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
#include <thread>

#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif

namespace hermes {
namespace hbc {
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/BCGen/HBC/BytecodeInstructionGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

#include <vector>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {
namespace hbc {

Expand Down
3 changes: 3 additions & 0 deletions include/hermes/Regex/RegexBytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#include <cstdint>
#include <vector>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {
namespace regex {

Expand Down
3 changes: 3 additions & 0 deletions include/hermes/SourceMap/SourceMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

#include <vector>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {

/// Represent a source location in original JS source file.
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/SourceMap/SourceMapGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#include <llvh/ADT/DenseMap.h>
#include <vector>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {

/// A class representing a JavaScript source map, version 3 only. It borrows
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/Support/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
#include <memory>
#include <vector>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {

/// A slab based BumpPtrAllocator where the pointer can be saved and restored.
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/Support/BigIntSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
#include <string>
#include <vector>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {
namespace bigint {

Expand Down
3 changes: 3 additions & 0 deletions include/hermes/Support/RegExpSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#include <memory>
#include <string>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace llvh {
class raw_ostream;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/ArrayLike.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
#include "hermes/VM/JSArray.h"
#include "hermes/VM/JSObject.h"
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {
namespace vm {

Expand Down
3 changes: 3 additions & 0 deletions include/hermes/VM/ArrayStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

#include "llvh/Support/TrailingObjects.h"
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {
namespace vm {

Expand Down
Loading

0 comments on commit 8a6a977

Please sign in to comment.