1 //===- TypeSize.cpp - Wrapper around type sizes------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "llvm/Support/TypeSize.h" 10 #include "llvm/Support/CommandLine.h" 11 12 using namespace llvm; 13 14 /// The ScalableErrorAsWarning is a temporary measure to suppress errors from 15 /// using the wrong interface on a scalable vector. 16 cl::opt<bool> ScalableErrorAsWarning( 17 "treat-scalable-fixed-error-as-warning", cl::Hidden, cl::init(false), 18 cl::desc("Treat issues where a fixed-width property is requested from a " 19 "scalable type as a warning, instead of an error."), 20 cl::ZeroOrMore); 21 reportInvalidSizeRequest(const char * Msg)22void llvm::reportInvalidSizeRequest(const char *Msg) { 23 #ifndef STRICT_FIXED_SIZE_VECTORS 24 if (ScalableErrorAsWarning) { 25 WithColor::warning() << "Invalid size request on a scalable vector; " << Msg 26 << "\n"; 27 return; 28 } 29 #endif 30 report_fatal_error("Invalid size request on a scalable vector."); 31 } 32 operator TypeSize::ScalarTy() const33TypeSize::operator TypeSize::ScalarTy() const { 34 if (isScalable()) { 35 reportInvalidSizeRequest( 36 "Cannot implicitly convert a scalable size to a fixed-width size in " 37 "`TypeSize::operator ScalarTy()`"); 38 return getKnownMinValue(); 39 } 40 return getFixedValue(); 41 } 42