@@ -923,4 +923,130 @@ CIRGenFunction::emitArrayLength(const clang::ArrayType *origArrayType,
923
923
return builder.getConstInt (*currSrcLoc, SizeTy, countFromCLAs);
924
924
}
925
925
926
+ // TODO(cir): Most of this function can be shared between CIRGen
927
+ // and traditional LLVM codegen
928
+ void CIRGenFunction::emitVariablyModifiedType (QualType type) {
929
+ assert (type->isVariablyModifiedType () &&
930
+ " Must pass variably modified type to EmitVLASizes!" );
931
+
932
+ // We're going to walk down into the type and look for VLA
933
+ // expressions.
934
+ do {
935
+ assert (type->isVariablyModifiedType ());
936
+
937
+ const Type *ty = type.getTypePtr ();
938
+ switch (ty->getTypeClass ()) {
939
+ case Type::CountAttributed:
940
+ case Type::PackIndexing:
941
+ case Type::ArrayParameter:
942
+ case Type::HLSLAttributedResource:
943
+ case Type::HLSLInlineSpirv:
944
+ case Type::PredefinedSugar:
945
+ cgm.errorNYI (" CIRGenFunction::emitVariablyModifiedType" );
946
+
947
+ #define TYPE (Class, Base )
948
+ #define ABSTRACT_TYPE (Class, Base )
949
+ #define NON_CANONICAL_TYPE (Class, Base )
950
+ #define DEPENDENT_TYPE (Class, Base ) case Type::Class:
951
+ #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE (Class, Base )
952
+ #include " clang/AST/TypeNodes.inc"
953
+ llvm_unreachable (
954
+ " dependent type must be resolved before the CIR codegen" );
955
+
956
+ // These types are never variably-modified.
957
+ case Type::Builtin:
958
+ case Type::Complex:
959
+ case Type::Vector:
960
+ case Type::ExtVector:
961
+ case Type::ConstantMatrix:
962
+ case Type::Record:
963
+ case Type::Enum:
964
+ case Type::Using:
965
+ case Type::TemplateSpecialization:
966
+ case Type::ObjCTypeParam:
967
+ case Type::ObjCObject:
968
+ case Type::ObjCInterface:
969
+ case Type::ObjCObjectPointer:
970
+ case Type::BitInt:
971
+ llvm_unreachable (" type class is never variably-modified!" );
972
+
973
+ case Type::Elaborated:
974
+ type = cast<clang::ElaboratedType>(ty)->getNamedType ();
975
+ break ;
976
+
977
+ case Type::Adjusted:
978
+ type = cast<clang::AdjustedType>(ty)->getAdjustedType ();
979
+ break ;
980
+
981
+ case Type::Decayed:
982
+ type = cast<clang::DecayedType>(ty)->getPointeeType ();
983
+ break ;
984
+
985
+ case Type::Pointer:
986
+ type = cast<clang::PointerType>(ty)->getPointeeType ();
987
+ break ;
988
+
989
+ case Type::BlockPointer:
990
+ type = cast<clang::BlockPointerType>(ty)->getPointeeType ();
991
+ break ;
992
+
993
+ case Type::LValueReference:
994
+ case Type::RValueReference:
995
+ type = cast<clang::ReferenceType>(ty)->getPointeeType ();
996
+ break ;
997
+
998
+ case Type::MemberPointer:
999
+ type = cast<clang::MemberPointerType>(ty)->getPointeeType ();
1000
+ break ;
1001
+
1002
+ case Type::ConstantArray:
1003
+ case Type::IncompleteArray:
1004
+ // Losing element qualification here is fine.
1005
+ type = cast<clang::ArrayType>(ty)->getElementType ();
1006
+ break ;
1007
+
1008
+ case Type::VariableArray: {
1009
+ cgm.errorNYI (" CIRGenFunction::emitVariablyModifiedType VLA" );
1010
+ break ;
1011
+ }
1012
+
1013
+ case Type::FunctionProto:
1014
+ case Type::FunctionNoProto:
1015
+ type = cast<clang::FunctionType>(ty)->getReturnType ();
1016
+ break ;
1017
+
1018
+ case Type::Paren:
1019
+ case Type::TypeOf:
1020
+ case Type::UnaryTransform:
1021
+ case Type::Attributed:
1022
+ case Type::BTFTagAttributed:
1023
+ case Type::SubstTemplateTypeParm:
1024
+ case Type::MacroQualified:
1025
+ // Keep walking after single level desugaring.
1026
+ type = type.getSingleStepDesugaredType (getContext ());
1027
+ break ;
1028
+
1029
+ case Type::Typedef:
1030
+ case Type::Decltype:
1031
+ case Type::Auto:
1032
+ case Type::DeducedTemplateSpecialization:
1033
+ // Stop walking: nothing to do.
1034
+ return ;
1035
+
1036
+ case Type::TypeOfExpr:
1037
+ // Stop walking: emit typeof expression.
1038
+ emitIgnoredExpr (cast<clang::TypeOfExprType>(ty)->getUnderlyingExpr ());
1039
+ return ;
1040
+
1041
+ case Type::Atomic:
1042
+ type = cast<clang::AtomicType>(ty)->getValueType ();
1043
+ break ;
1044
+
1045
+ case Type::Pipe:
1046
+ type = cast<clang::PipeType>(ty)->getElementType ();
1047
+ break ;
1048
+ }
1049
+ } while (type->isVariablyModifiedType ());
1050
+ }
1051
+
926
1052
} // namespace clang::CIRGen
0 commit comments