Skip to content

Commit a913edb

Browse files
author
Ettore Tiotto
authored
Change -Wno-everything to -w to account for old GNU toolchains. (llvm#935)
Signed-off-by: Ettore Tiotto <[email protected]>
1 parent b737e33 commit a913edb

File tree

8 files changed

+105
-28
lines changed

8 files changed

+105
-28
lines changed

CMakeLists.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cmake_minimum_required(VERSION 3.13.4)
66
project(onnx-mlir)
77

88
option(ONNX_MLIR_BUILD_TESTS "Build ONNX MLIR test executables. If OFF, just generate build targets." ON)
9+
option(ONNX_MLIR_SUPPRESS_THIRD_PARTY_WARNINGS "Suppress warning in third_party code." ON)
910

1011
set(CMAKE_CXX_STANDARD 14)
1112

@@ -96,7 +97,33 @@ elseif ((ONNX_USE_PROTOBUF_SHARED_LIBS AND Protobuf_USE_STATIC_LIBS)
9697
"ONNX_USE_PROTOBUF_SHARED_LIBS and Protobuf_USE_STATIC_LIBS must be opposites of each other.")
9798
endif()
9899

99-
add_subdirectory(third_party)
100+
# Suppress warnings in third party code.
101+
if (ONNX_MLIR_SUPPRESS_THIRD_PARTY_WARNINGS)
102+
set(CMAKE_C_FLAGS_COPY ${CMAKE_C_FLAGS})
103+
set(CMAKE_CXX_FLAGS_COPY ${CMAKE_CXX_FLAGS})
104+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
105+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
106+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
107+
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
108+
# MSVC complains when overriding existing warning levels flags, remove
109+
# them and add "/W".
110+
STRING(REGEX REPLACE "/W[0-9]" "/W0" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
111+
STRING(REGEX REPLACE "/W[0-9]" "/W0" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
112+
endif()
113+
endif()
114+
115+
add_subdirectory(third_party/onnx)
116+
add_subdirectory(third_party/pybind11)
117+
add_subdirectory(third_party/rapidcheck)
118+
119+
# Ensure warnings are reported for onnx-mlir code.
120+
if (ONNX_MLIR_SUPPRESS_THIRD_PARTY_WARNINGS)
121+
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_COPY})
122+
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_COPY})
123+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSUPPRESS_THIRD_PARTY_WARNINGS")
124+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSUPPRESS_THIRD_PARTY_WARNINGS")
125+
endif()
126+
100127
add_subdirectory(utils)
101128
add_subdirectory(include)
102129
add_subdirectory(src)

src/Builder/FrontendDialectTransformer.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,25 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
#include <type_traits>
21+
#include "FrontendDialectTransformer.hpp"
22+
#include "src/Interface/HasOnnxSubgraphOpInterface.hpp"
23+
#include "src/Interface/ResultTypeInferenceOpInterface.hpp"
24+
#include "src/Support/SuppressWarnings.h"
2225

2326
#include "mlir/IR/BuiltinOps.h"
24-
#include "onnx/defs/schema.h"
2527
#include "llvm/ADT/TypeSwitch.h"
2628

29+
SUPPRESS_WARNINGS_PUSH
2730
#include "onnx/checker.h"
31+
#include "onnx/defs/schema.h"
2832
#include "onnx/shape_inference/implementation.h"
2933
#include "onnx/version_converter/convert.h"
34+
SUPPRESS_WARNINGS_POP
3035

31-
#include "src/Interface/HasOnnxSubgraphOpInterface.hpp"
32-
#include "src/Interface/ResultTypeInferenceOpInterface.hpp"
33-
34-
#include "FrontendDialectTransformer.hpp"
3536
#include <fstream>
3637
#include <iostream>
3738
#include <map>
39+
#include <type_traits>
3840

3941
using namespace mlir;
4042

src/Conversion/KrnlToLLVM/KrnlToLLVM.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ class KrnlGetRefOpLowering : public ConvertToLLVMPattern {
278278

279279
LogicalResult matchAndRewrite(Operation *op, ArrayRef<Value> operands,
280280
ConversionPatternRewriter &rewriter) const override {
281-
KrnlGetRefOp getRefOp = llvm::dyn_cast<KrnlGetRefOp>(op);
282281
auto loc = op->getLoc();
283282

284283
KrnlGetRefOpAdaptor operandAdaptor(operands);

src/Runtime/jni/jniwrapper.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ OMTensorList *omtl_java_to_native(
260260
* in the OMTensor.
261261
*/
262262
LIB_VAR_CALL(jni_omts[i],
263-
omTensorCreate(jni_data, jni_shape, jni_rank, jni_dataType), NULL, env,
264-
japi->jecpt_cls, "jni_omts[%d]=null", i);
263+
omTensorCreate(jni_data, (int64_t *)jni_shape, jni_rank, jni_dataType),
264+
NULL, env, japi->jecpt_cls, "jni_omts[%d]=null", i);
265265

266266
/* Release reference to the java objects */
267267
JNI_CALL(
@@ -339,14 +339,14 @@ jobject omtl_native_to_java(
339339
/* Create data shape array Java object, fill in from native array */
340340
JNI_TYPE_VAR_CALL(
341341
env, jlongArray, jomt_shape, (*env)->NewLongArray(env, jni_rank));
342-
JNI_CALL(env,
343-
(*env)->SetLongArrayRegion(env, jomt_shape, 0, jni_rank, jni_shape));
342+
JNI_CALL(env, (*env)->SetLongArrayRegion(
343+
env, jomt_shape, 0, jni_rank, (jlong *)jni_shape));
344344

345345
/* Create data strides array Java object, fill in from native array */
346346
JNI_TYPE_VAR_CALL(
347347
env, jlongArray, jomt_strides, (*env)->NewLongArray(env, jni_rank));
348348
JNI_CALL(env, (*env)->SetLongArrayRegion(
349-
env, jomt_strides, 0, jni_rank, jni_strides));
349+
env, jomt_strides, 0, jni_rank, (jlong *)jni_strides));
350350

351351
/* Primitive type int can be directly used. Call setDataType method */
352352
int jomt_dataType = jni_dataType;

src/Support/Common.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
//====--------------- Common.hpp - Common Utilities -----------------------===//
6+
//
7+
// Copyright 2021 The IBM Research Authors.
8+
//
9+
// =============================================================================
10+
//
11+
// This file contains common utilities and support code.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
115
#pragma once
216

317
#if defined(__GNUC__) || defined(__clang__)

src/Support/SuppressWarnings.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
//====--------------- SuppressWarnings.h - Suppress Warnings --------------===//
6+
//
7+
// Copyright 2021 The IBM Research Authors.
8+
//
9+
// =============================================================================
10+
//
11+
// This file contains support code used to suppress warnings.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#pragma once
16+
17+
// clang-format off
18+
#if defined(SUPPRESS_THIRD_PARTY_WARNINGS)
19+
#if defined(__clang__)
20+
#define SUPPRESS_WARNINGS_PUSH \
21+
_Pragma("clang diagnostic push") \
22+
_Pragma("clang diagnostic ignored \"-Wcast-qual\"") \
23+
_Pragma("clang diagnostic ignored \"-Wstring-conversion\"") \
24+
_Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") \
25+
_Pragma("clang diagnostic ignored \"-Wsuggest-override\"")
26+
27+
#define SUPPRESS_WARNINGS_POP _Pragma("clang diagnostic pop")
28+
#elif defined(__GNUC__)
29+
#define SUPPRESS_WARNINGS_PUSH \
30+
_Pragma("GCC diagnostic push") \
31+
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
32+
_Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"") \
33+
_Pragma("GCC diagnostic ignored \"-Wsuggest-override\"")
34+
35+
#define SUPPRESS_WARNINGS_POP _Pragma("GCC diagnostic pop")
36+
#else
37+
#define SUPPRESS_WARNINGS_PUSH
38+
#define SUPPRESS_WARNINGS_POP
39+
#endif
40+
#else
41+
#define SUPPRESS_WARNINGS_PUSH
42+
#define SUPPRESS_WARNINGS_POP
43+
#endif
44+
// clang-format on

test/onnx2mlir/CustomFnTest.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212
#include "mlir/Pass/PassManager.h"
1313
#include "mlir/Transforms/Passes.h"
1414

15-
#pragma clang diagnostic ignored "-Weverything"
16-
#pragma gcc diagnostic ignored "-Weverything"
17-
#include "onnx/defs/function.h"
18-
#include "onnx/defs/schema.h"
19-
#pragma clang diagnostic pop
20-
#pragma gcc diagnostic pop
21-
2215
#include "src/Builder/FrontendDialectTransformer.hpp"
2316
#include "src/Interface/ShapeInferenceOpInterface.hpp"
2417
#include "src/Pass/Passes.hpp"
18+
#include "src/Support/SuppressWarnings.h"
19+
20+
SUPPRESS_WARNINGS_PUSH
21+
#include "onnx/defs/function.h"
22+
#include "onnx/defs/schema.h"
23+
SUPPRESS_WARNINGS_POP
2524

2625
using namespace std;
2726
using namespace ONNX_NAMESPACE;

third_party/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)