public static VariableStorage checkStorage(Function function, VariableStorage storage,
			DataType dataType, boolean allowSizeMismatch) throws InvalidInputException {
		if (!storage.isValid()) {
			return storage; // allow BAD and UNASSIGNED to pass thru
		}
		DataType baseType = dataType;
		if (baseType instanceof TypeDef) {
			baseType = ((TypeDef) baseType).getBaseDataType();
		}
		int storageSize = storage.size();
		int dtLen = dataType.getLength();
		if (baseType instanceof VoidDataType) {
			storage = VariableStorage.VOID_STORAGE;
		}
		else if (storage.isUniqueStorage() || storage.isConstantStorage()) {
			throw new InvalidInputException("Invalid storage address specified: " + storage);
		}
		else if (dtLen == 0 && (baseType instanceof Structure)) {
			storage = VariableStorage.UNASSIGNED_STORAGE;
		}
		else if (!allowSizeMismatch && storageSize != dtLen) {
			if (dataType instanceof AbstractFloatDataType) {
				return storage;  // do not constrain or attempt resize of float storage
			}
			if (function != null) {
				return resizeStorage(storage, dataType, true, function);
			}
			if (dtLen < storageSize && storage.isRegisterStorage()) {
				// TODO: this could be expanded to handle other storage
				return new VariableStorage(storage.getProgramArchitecture(),
					shrinkRegister(storage.getRegister(), storageSize - dtLen));
			}
			throw new InvalidInputException(
				"Storage size does not match data type size: " + dataType.getLength());
		}
		return storage;
	}
Perform variable storage checks using the specified datatype.
@param function if specified and variable storage size does not match the data-type size
an attempt will be made to resize the specified storage.
@param storage variable storage
@param dataType a datatype checked using {@link #checkDataType(DataType, boolean, int, Program)}
@param allowSizeMismatch if true size mismatch will be ignore
@return original storage or resized storage with the correct size.
@throws InvalidInputException if specified storage is not suitable for datatype
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/VariableUtilities.java