File: FortranVariableInterface.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (69 lines) | stat: -rw-r--r-- 3,133 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//===-- FortranVariableInterface.cpp.cpp ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
//
//===----------------------------------------------------------------------===//

#include "flang/Optimizer/Dialect/FortranVariableInterface.h"

#include "flang/Optimizer/Dialect/FortranVariableInterface.cpp.inc"

mlir::LogicalResult
fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) {
  const unsigned numExplicitTypeParams = getExplicitTypeParams().size();
  mlir::Type memType = memref.getType();
  const bool sourceIsBoxValue = memType.isa<fir::BaseBoxType>();
  const bool sourceIsBoxAddress = fir::isBoxAddress(memType);
  const bool sourceIsBox = sourceIsBoxValue || sourceIsBoxAddress;
  if (isCharacter()) {
    if (numExplicitTypeParams > 1)
      return emitOpError(
          "of character entity must have at most one length parameter");
    if (numExplicitTypeParams == 0 && !sourceIsBox)
      return emitOpError("must be provided exactly one type parameter when its "
                         "base is a character that is not a box");

  } else if (auto recordType = getElementType().dyn_cast<fir::RecordType>()) {
    if (numExplicitTypeParams < recordType.getNumLenParams() && !sourceIsBox)
      return emitOpError("must be provided all the derived type length "
                         "parameters when the base is not a box");
    if (numExplicitTypeParams > recordType.getNumLenParams())
      return emitOpError("has too many length parameters");
  } else if (numExplicitTypeParams != 0) {
    return emitOpError("of numeric, logical, or assumed type entity must not "
                       "have length parameters");
  }

  if (isArray()) {
    if (mlir::Value shape = getShape()) {
      if (sourceIsBoxAddress)
        return emitOpError("for box address must not have a shape operand");
      unsigned shapeRank = 0;
      if (auto shapeType = shape.getType().dyn_cast<fir::ShapeType>()) {
        shapeRank = shapeType.getRank();
      } else if (auto shapeShiftType =
                     shape.getType().dyn_cast<fir::ShapeShiftType>()) {
        shapeRank = shapeShiftType.getRank();
      } else {
        if (!sourceIsBoxValue)
          emitOpError("of array entity with a raw address base must have a "
                      "shape operand that is a shape or shapeshift");
        shapeRank = shape.getType().cast<fir::ShiftType>().getRank();
      }

      std::optional<unsigned> rank = getRank();
      if (!rank || *rank != shapeRank)
        return emitOpError("has conflicting shape and base operand ranks");
    } else if (!sourceIsBox) {
      emitOpError("of array entity with a raw address base must have a shape "
                  "operand that is a shape or shapeshift");
    }
  }
  return mlir::success();
}