[llvm] d5746d7 - eliminating g++ warnings (#105520)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 13:20:52 PDT 2024


Author: Frank Schlimbach
Date: 2024-10-18T21:20:47+01:00
New Revision: d5746d73cedcf7a593dc4b4f2ce2465e2d45750b

URL: https://github.com/llvm/llvm-project/commit/d5746d73cedcf7a593dc4b4f2ce2465e2d45750b
DIFF: https://github.com/llvm/llvm-project/commit/d5746d73cedcf7a593dc4b4f2ce2465e2d45750b.diff

LOG: eliminating g++ warnings (#105520)

Eliminating g++ warnings. Mostly declaring "[[maybe_unused]]", adding
return statements where missing and fixing casts.

@rengolin

---------

Co-authored-by: Benjamin Maxwell <macdue at dueutil.tech>
Co-authored-by: Renato Golin <rengolin at systemcall.eu>

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    mlir/CMakeLists.txt
    mlir/lib/CAPI/IR/IR.cpp
    mlir/lib/Conversion/ArmSMEToLLVM/ArmSMEToLLVM.cpp
    mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp
    mlir/lib/Debug/DebuggerExecutionContextHook.cpp
    mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
    mlir/lib/Dialect/ArmSME/Transforms/TileAllocation.cpp
    mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp
    mlir/lib/Dialect/Index/IR/IndexOps.cpp
    mlir/lib/Transforms/Utils/DialectConversion.cpp
    mlir/unittests/Bytecode/BytecodeTest.cpp
    mlir/unittests/Support/CyclicReplacerCacheTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 327e7f7f8a1ed8..bf4c707cca06d5 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2849,7 +2849,7 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI,
 
   if (isElf) {
     MCSymbolELF *LinkedToSym = dyn_cast<MCSymbolELF>(CurrentFnSym);
-    int Flags = F.hasComdat() ? (unsigned)ELF::SHF_GROUP : 0;
+    int Flags = F.hasComdat() ? static_cast<int>(ELF::SHF_GROUP) : 0;
 
     JumpTableSizesSection = OutContext.getELFSection(
         sectionName, ELF::SHT_LLVM_JT_SIZES, Flags, 0, GroupName, F.hasComdat(),

diff  --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index c6d44908a1111d..599a1cbaafd855 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -84,13 +84,20 @@ check_c_compiler_flag("-Werror=mismatched-tags" C_SUPPORTS_WERROR_MISMATCHED_TAG
 append_if(C_SUPPORTS_WERROR_MISMATCHED_TAGS "-Werror=mismatched-tags" CMAKE_C_FLAGS)
 append_if(C_SUPPORTS_WERROR_MISMATCHED_TAGS "-Werror=mismatched-tags" CMAKE_CXX_FLAGS)
 
-# Silence a false positive GCC -Wunused-but-set-parameter warning in constexpr
-# cases, by marking SelectedCase as used. See
-# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85827 for details. The issue is
-# fixed in GCC 10.
-if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0")
-  check_cxx_compiler_flag("-Wno-unused-but-set-parameter" CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER)
-  append_if(CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER "-Wno-unused-but-set-parameter" CMAKE_CXX_FLAGS)
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+  # Silence a false positive GCC -Wunused-but-set-parameter warning in
+  # constexpr cases. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85827
+  # for details
+  if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14.0")
+    check_cxx_compiler_flag("-Wno-unused-but-set-parameter" CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER)
+    append_if(CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER "-Wno-unused-but-set-parameter" CMAKE_CXX_FLAGS)
+  endif()
+  # Silence a false positive GCC -Wdeprecated-copy warning in cases where
+  # a copy operator is defined through "using" a base class copy operator.
+  if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "12.0")
+    check_cxx_compiler_flag("-Wno-deprecated-copy" CXX_SUPPORTS_WNO_DEPRECTAED_COPY)
+    append_if(CXX_SUPPORTS_WNO_DEPRECTAED_COPY "-Wno-deprecated-copy" CMAKE_CXX_FLAGS)
+  endif()
 endif()
 
 # Installing the headers and docs needs to depend on generating any public

diff  --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp
index 5eb531b70aee05..e7e6b11c81b9d3 100644
--- a/mlir/lib/CAPI/IR/IR.cpp
+++ b/mlir/lib/CAPI/IR/IR.cpp
@@ -736,6 +736,7 @@ static mlir::WalkResult unwrap(MlirWalkResult result) {
   case MlirWalkResultSkip:
     return mlir::WalkResult::skip();
   }
+  llvm_unreachable("unknown result in WalkResult::unwrap");
 }
 
 void mlirOperationWalk(MlirOperation op, MlirOperationWalkCallback callback,

diff  --git a/mlir/lib/Conversion/ArmSMEToLLVM/ArmSMEToLLVM.cpp b/mlir/lib/Conversion/ArmSMEToLLVM/ArmSMEToLLVM.cpp
index f1fa411b82914a..40a3489f7a4d7b 100644
--- a/mlir/lib/Conversion/ArmSMEToLLVM/ArmSMEToLLVM.cpp
+++ b/mlir/lib/Conversion/ArmSMEToLLVM/ArmSMEToLLVM.cpp
@@ -81,6 +81,7 @@ static Operation *createLoadTileSliceIntrinsic(
       break;
     }
   }
+  llvm_unreachable("unknown type in createLoadTileSliceIntrinsic");
 }
 
 /// Helper to create an arm_sme.intr.st1*.(horiz|vert)' intrinsic.
@@ -125,6 +126,7 @@ static Operation *createStoreTileSliceIntrinsic(
           loc, maskOp, ptr, tileId, tileSliceI32);
     }
   }
+  llvm_unreachable("unknown type in createStoreTileSliceIntrinsic");
 }
 
 IntegerAttr getTileIdOrError(arm_sme::ArmSMETileOpInterface op) {
@@ -850,6 +852,7 @@ struct StreamingVLOpConversion
       case arm_sme::TypeSize::Double:
         return rewriter.create<arm_sme::aarch64_sme_cntsd>(loc, i64Type);
       }
+      llvm_unreachable("unknown type size in StreamingVLOpConversion");
     }();
     rewriter.replaceOpWithNewOp<arith::IndexCastOp>(
         streamingVlOp, rewriter.getIndexType(), intrOp->getResult(0));

diff  --git a/mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp b/mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp
index b4cc8324883eeb..7c441830e1e3be 100644
--- a/mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp
+++ b/mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp
@@ -310,6 +310,7 @@ struct ConvertIndexCmpPattern final : OpConversionPattern<CmpOp> {
     case IndexCmpPredicate::ULT:
       return rewriteCmpOp<spirv::ULessThanOp>(op, adaptor, rewriter);
     }
+    llvm_unreachable("Unknown predicate in ConvertIndexCmpPattern");
   }
 };
 

diff  --git a/mlir/lib/Debug/DebuggerExecutionContextHook.cpp b/mlir/lib/Debug/DebuggerExecutionContextHook.cpp
index 744a0380ec710b..863113928d5b4f 100644
--- a/mlir/lib/Debug/DebuggerExecutionContextHook.cpp
+++ b/mlir/lib/Debug/DebuggerExecutionContextHook.cpp
@@ -301,7 +301,7 @@ void mlirDebuggerAddFileLineColLocBreakpoint(const char *file, int line,
 
 LLVM_ATTRIBUTE_NOINLINE void mlirDebuggerBreakpointHook() {
   static LLVM_THREAD_LOCAL void *volatile sink;
-  sink = (void *)&sink;
+  sink = static_cast<void *>(const_cast<void **>(&sink));
 }
 
 static void preventLinkerDeadCodeElim() {
@@ -321,7 +321,7 @@ static void preventLinkerDeadCodeElim() {
     sink = (void *)mlirDebuggerAddTagBreakpoint;
     sink = (void *)mlirDebuggerAddRewritePatternBreakpoint;
     sink = (void *)mlirDebuggerAddFileLineColLocBreakpoint;
-    sink = (void *)&sink;
+    sink = static_cast<void *>(const_cast<void **>(&sink));
     return true;
   }();
   (void)initialized;

diff  --git a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
index 63447baa31eb0c..492e4781f57810 100644
--- a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
+++ b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp
@@ -349,7 +349,7 @@ LogicalResult DPPOp::verify() {
       return emitOpError("quad_perm attribute must have exactly 4 elements");
     }
     for (auto elem : quadPermAttr.getAsRange<IntegerAttr>()) {
-      uint32_t num = elem.getInt();
+      int32_t num = elem.getInt();
       if (num < 0 || num > 3) {
         return emitOpError(
             "Each element of quad_perm must be in the range [0, 3]");

diff  --git a/mlir/lib/Dialect/ArmSME/Transforms/TileAllocation.cpp b/mlir/lib/Dialect/ArmSME/Transforms/TileAllocation.cpp
index 3a2042d23e5346..84556fbefbc9ff 100644
--- a/mlir/lib/Dialect/ArmSME/Transforms/TileAllocation.cpp
+++ b/mlir/lib/Dialect/ArmSME/Transforms/TileAllocation.cpp
@@ -137,6 +137,7 @@ static ArrayRef<TileMask> getMasks(ArmSMETileType type) {
   case ArmSMETileType::ZAQ:
     return ZA_Q_MASKS;
   }
+  llvm_unreachable("unknown type in getMasks");
 }
 
 class TileAllocator {

diff  --git a/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp b/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp
index 8c3e25355f6087..273101ce5f3e78 100644
--- a/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp
+++ b/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp
@@ -141,7 +141,6 @@ struct ParallelComputeFunctionArgs {
   BlockArgument blockSize();
   ArrayRef<BlockArgument> tripCounts();
   ArrayRef<BlockArgument> lowerBounds();
-  ArrayRef<BlockArgument> upperBounds();
   ArrayRef<BlockArgument> steps();
   ArrayRef<BlockArgument> captures();
 
@@ -175,10 +174,6 @@ ArrayRef<BlockArgument> ParallelComputeFunctionArgs::lowerBounds() {
   return args.drop_front(2 + 1 * numLoops).take_front(numLoops);
 }
 
-ArrayRef<BlockArgument> ParallelComputeFunctionArgs::upperBounds() {
-  return args.drop_front(2 + 2 * numLoops).take_front(numLoops);
-}
-
 ArrayRef<BlockArgument> ParallelComputeFunctionArgs::steps() {
   return args.drop_front(2 + 3 * numLoops).take_front(numLoops);
 }

diff  --git a/mlir/lib/Dialect/Index/IR/IndexOps.cpp b/mlir/lib/Dialect/Index/IR/IndexOps.cpp
index 42401dae217ce1..5ad989b7da126e 100644
--- a/mlir/lib/Dialect/Index/IR/IndexOps.cpp
+++ b/mlir/lib/Dialect/Index/IR/IndexOps.cpp
@@ -594,6 +594,7 @@ static bool compareSameArgs(IndexCmpPredicate pred) {
   case IndexCmpPredicate::ULT:
     return false;
   }
+  llvm_unreachable("unknown predicate in compareSameArgs");
 }
 
 OpFoldResult CmpOp::fold(FoldAdaptor adaptor) {

diff  --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 1baddd881f6aa2..b8d0329906a867 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -1045,9 +1045,8 @@ UnresolvedMaterializationRewrite::UnresolvedMaterializationRewrite(
     const TypeConverter *converter, MaterializationKind kind, Type originalType)
     : OperationRewrite(Kind::UnresolvedMaterialization, rewriterImpl, op),
       converterAndKind(converter, kind), originalType(originalType) {
-  assert(!originalType ||
-         kind == MaterializationKind::Target &&
-             "original type is valid only for target materializations");
+  assert((!originalType || kind == MaterializationKind::Target) &&
+         "original type is valid only for target materializations");
   rewriterImpl.unresolvedMaterializations[op] = this;
 }
 
@@ -1337,9 +1336,8 @@ Value ConversionPatternRewriterImpl::buildUnresolvedMaterialization(
     MaterializationKind kind, OpBuilder::InsertPoint ip, Location loc,
     ValueRange inputs, Type outputType, Type originalType,
     const TypeConverter *converter) {
-  assert(!originalType ||
-         kind == MaterializationKind::Target &&
-             "original type is valid only for target materializations");
+  assert((!originalType || kind == MaterializationKind::Target) &&
+         "original type is valid only for target materializations");
 
   // Avoid materializing an unnecessary cast.
   if (inputs.size() == 1 && inputs.front().getType() == outputType)

diff  --git a/mlir/unittests/Bytecode/BytecodeTest.cpp b/mlir/unittests/Bytecode/BytecodeTest.cpp
index 0342f294f38d6d..baf5d5c650e309 100644
--- a/mlir/unittests/Bytecode/BytecodeTest.cpp
+++ b/mlir/unittests/Bytecode/BytecodeTest.cpp
@@ -54,7 +54,7 @@ TEST(Bytecode, MultiModuleWithResource) {
   constexpr size_t kAlignment = 0x20;
   size_t bufferSize = buffer.size();
   buffer.reserve(bufferSize + kAlignment - 1);
-  size_t pad = ~(uintptr_t)buffer.data() + 1 & kAlignment - 1;
+  size_t pad = (~(uintptr_t)buffer.data() + 1) & (kAlignment - 1);
   buffer.insert(0, pad, ' ');
   StringRef alignedBuffer(buffer.data() + pad, bufferSize);
 

diff  --git a/mlir/unittests/Support/CyclicReplacerCacheTest.cpp b/mlir/unittests/Support/CyclicReplacerCacheTest.cpp
index 64a8ab72b69b7d..26f0709f7d8310 100644
--- a/mlir/unittests/Support/CyclicReplacerCacheTest.cpp
+++ b/mlir/unittests/Support/CyclicReplacerCacheTest.cpp
@@ -225,7 +225,8 @@ class CachedCyclicReplacerGraphReplacement : public ::testing::Test {
     /// Add a recursive-self-node, i.e. a duplicate of the original node that is
     /// meant to represent an indirection to it.
     std::pair<Node, int64_t> addRecursiveSelfNode(Graph::Node originalId) {
-      return {addNode(originalId, nextRecursionId), nextRecursionId++};
+      auto node = addNode(originalId, nextRecursionId);
+      return {node, nextRecursionId++};
     }
     void addEdge(Node src, Node sink) { connections.addEdge(src, sink); }
 


        


More information about the llvm-commits mailing list