@@ -677,6 +677,100 @@ enum class VarArgKind {
677
677
Invalid
678
678
};
679
679
680
+ /// AssignConvertType - All of the 'assignment' semantic checks return this
681
+ /// enum to indicate whether the assignment was allowed. These checks are
682
+ /// done for simple assignments, as well as initialization, return from
683
+ /// function, argument passing, etc. The query is phrased in terms of a
684
+ /// source and destination type.
685
+ enum class AssignConvertType {
686
+ /// Compatible - the types are compatible according to the standard.
687
+ Compatible,
688
+
689
+ /// CompatibleVoidPtrToNonVoidPtr - The types are compatible in C because
690
+ /// a void * can implicitly convert to another pointer type, which we
691
+ /// differentiate for better diagnostic behavior.
692
+ CompatibleVoidPtrToNonVoidPtr,
693
+
694
+ /// PointerToInt - The assignment converts a pointer to an int, which we
695
+ /// accept as an extension.
696
+ PointerToInt,
697
+
698
+ /// IntToPointer - The assignment converts an int to a pointer, which we
699
+ /// accept as an extension.
700
+ IntToPointer,
701
+
702
+ /// FunctionVoidPointer - The assignment is between a function pointer and
703
+ /// void*, which the standard doesn't allow, but we accept as an extension.
704
+ FunctionVoidPointer,
705
+
706
+ /// IncompatiblePointer - The assignment is between two pointers types that
707
+ /// are not compatible, but we accept them as an extension.
708
+ IncompatiblePointer,
709
+
710
+ /// IncompatibleFunctionPointer - The assignment is between two function
711
+ /// pointers types that are not compatible, but we accept them as an
712
+ /// extension.
713
+ IncompatibleFunctionPointer,
714
+
715
+ /// IncompatibleFunctionPointerStrict - The assignment is between two
716
+ /// function pointer types that are not identical, but are compatible,
717
+ /// unless compiled with -fsanitize=cfi, in which case the type mismatch
718
+ /// may trip an indirect call runtime check.
719
+ IncompatibleFunctionPointerStrict,
720
+
721
+ /// IncompatiblePointerSign - The assignment is between two pointers types
722
+ /// which point to integers which have a different sign, but are otherwise
723
+ /// identical. This is a subset of the above, but broken out because it's by
724
+ /// far the most common case of incompatible pointers.
725
+ IncompatiblePointerSign,
726
+
727
+ /// CompatiblePointerDiscardsQualifiers - The assignment discards
728
+ /// c/v/r qualifiers, which we accept as an extension.
729
+ CompatiblePointerDiscardsQualifiers,
730
+
731
+ /// IncompatiblePointerDiscardsQualifiers - The assignment
732
+ /// discards qualifiers that we don't permit to be discarded,
733
+ /// like address spaces.
734
+ IncompatiblePointerDiscardsQualifiers,
735
+
736
+ /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment
737
+ /// changes address spaces in nested pointer types which is not allowed.
738
+ /// For instance, converting __private int ** to __generic int ** is
739
+ /// illegal even though __private could be converted to __generic.
740
+ IncompatibleNestedPointerAddressSpaceMismatch,
741
+
742
+ /// IncompatibleNestedPointerQualifiers - The assignment is between two
743
+ /// nested pointer types, and the qualifiers other than the first two
744
+ /// levels differ e.g. char ** -> const char **, but we accept them as an
745
+ /// extension.
746
+ IncompatibleNestedPointerQualifiers,
747
+
748
+ /// IncompatibleVectors - The assignment is between two vector types that
749
+ /// have the same size, which we accept as an extension.
750
+ IncompatibleVectors,
751
+
752
+ /// IntToBlockPointer - The assignment converts an int to a block
753
+ /// pointer. We disallow this.
754
+ IntToBlockPointer,
755
+
756
+ /// IncompatibleBlockPointer - The assignment is between two block
757
+ /// pointers types that are not compatible.
758
+ IncompatibleBlockPointer,
759
+
760
+ /// IncompatibleObjCQualifiedId - The assignment is between a qualified
761
+ /// id type and something else (that is incompatible with it). For example,
762
+ /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
763
+ IncompatibleObjCQualifiedId,
764
+
765
+ /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an
766
+ /// object with __weak qualifier.
767
+ IncompatibleObjCWeakRef,
768
+
769
+ /// Incompatible - We reject this conversion outright, it is invalid to
770
+ /// represent it in the AST.
771
+ Incompatible
772
+ };
773
+
680
774
/// Sema - This implements semantic analysis and AST building for C.
681
775
/// \nosubgrouping
682
776
class Sema final : public SemaBase {
@@ -7768,107 +7862,13 @@ class Sema final : public SemaBase {
7768
7862
QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
7769
7863
SourceLocation Loc, ArithConvKind ACK);
7770
7864
7771
- /// AssignConvertType - All of the 'assignment' semantic checks return this
7772
- /// enum to indicate whether the assignment was allowed. These checks are
7773
- /// done for simple assignments, as well as initialization, return from
7774
- /// function, argument passing, etc. The query is phrased in terms of a
7775
- /// source and destination type.
7776
- enum AssignConvertType {
7777
- /// Compatible - the types are compatible according to the standard.
7778
- Compatible,
7779
-
7780
- /// CompatibleVoidPtrToNonVoidPtr - The types are compatible in C because
7781
- /// a void * can implicitly convert to another pointer type, which we
7782
- /// differentiate for better diagnostic behavior.
7783
- CompatibleVoidPtrToNonVoidPtr,
7784
-
7785
- /// PointerToInt - The assignment converts a pointer to an int, which we
7786
- /// accept as an extension.
7787
- PointerToInt,
7788
-
7789
- /// IntToPointer - The assignment converts an int to a pointer, which we
7790
- /// accept as an extension.
7791
- IntToPointer,
7792
-
7793
- /// FunctionVoidPointer - The assignment is between a function pointer and
7794
- /// void*, which the standard doesn't allow, but we accept as an extension.
7795
- FunctionVoidPointer,
7796
-
7797
- /// IncompatiblePointer - The assignment is between two pointers types that
7798
- /// are not compatible, but we accept them as an extension.
7799
- IncompatiblePointer,
7800
-
7801
- /// IncompatibleFunctionPointer - The assignment is between two function
7802
- /// pointers types that are not compatible, but we accept them as an
7803
- /// extension.
7804
- IncompatibleFunctionPointer,
7805
-
7806
- /// IncompatibleFunctionPointerStrict - The assignment is between two
7807
- /// function pointer types that are not identical, but are compatible,
7808
- /// unless compiled with -fsanitize=cfi, in which case the type mismatch
7809
- /// may trip an indirect call runtime check.
7810
- IncompatibleFunctionPointerStrict,
7811
-
7812
- /// IncompatiblePointerSign - The assignment is between two pointers types
7813
- /// which point to integers which have a different sign, but are otherwise
7814
- /// identical. This is a subset of the above, but broken out because it's by
7815
- /// far the most common case of incompatible pointers.
7816
- IncompatiblePointerSign,
7817
-
7818
- /// CompatiblePointerDiscardsQualifiers - The assignment discards
7819
- /// c/v/r qualifiers, which we accept as an extension.
7820
- CompatiblePointerDiscardsQualifiers,
7821
-
7822
- /// IncompatiblePointerDiscardsQualifiers - The assignment
7823
- /// discards qualifiers that we don't permit to be discarded,
7824
- /// like address spaces.
7825
- IncompatiblePointerDiscardsQualifiers,
7826
-
7827
- /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment
7828
- /// changes address spaces in nested pointer types which is not allowed.
7829
- /// For instance, converting __private int ** to __generic int ** is
7830
- /// illegal even though __private could be converted to __generic.
7831
- IncompatibleNestedPointerAddressSpaceMismatch,
7832
-
7833
- /// IncompatibleNestedPointerQualifiers - The assignment is between two
7834
- /// nested pointer types, and the qualifiers other than the first two
7835
- /// levels differ e.g. char ** -> const char **, but we accept them as an
7836
- /// extension.
7837
- IncompatibleNestedPointerQualifiers,
7838
-
7839
- /// IncompatibleVectors - The assignment is between two vector types that
7840
- /// have the same size, which we accept as an extension.
7841
- IncompatibleVectors,
7842
-
7843
- /// IntToBlockPointer - The assignment converts an int to a block
7844
- /// pointer. We disallow this.
7845
- IntToBlockPointer,
7846
-
7847
- /// IncompatibleBlockPointer - The assignment is between two block
7848
- /// pointers types that are not compatible.
7849
- IncompatibleBlockPointer,
7850
-
7851
- /// IncompatibleObjCQualifiedId - The assignment is between a qualified
7852
- /// id type and something else (that is incompatible with it). For example,
7853
- /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
7854
- IncompatibleObjCQualifiedId,
7855
-
7856
- /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an
7857
- /// object with __weak qualifier.
7858
- IncompatibleObjCWeakRef,
7859
-
7860
- /// Incompatible - We reject this conversion outright, it is invalid to
7861
- /// represent it in the AST.
7862
- Incompatible
7863
- };
7864
-
7865
7865
bool IsAssignConvertCompatible(AssignConvertType ConvTy) {
7866
7866
switch (ConvTy) {
7867
7867
default:
7868
7868
return false;
7869
- case Compatible:
7870
- case CompatiblePointerDiscardsQualifiers:
7871
- case CompatibleVoidPtrToNonVoidPtr:
7869
+ case AssignConvertType:: Compatible:
7870
+ case AssignConvertType:: CompatiblePointerDiscardsQualifiers:
7871
+ case AssignConvertType:: CompatibleVoidPtrToNonVoidPtr:
7872
7872
return true;
7873
7873
}
7874
7874
llvm_unreachable("impossible");
0 commit comments