| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: decl.c,v 1.203 2021/07/15 22:47:17 rillig Exp $ */ | | 1 | /* $NetBSD: decl.c,v 1.204 2021/07/15 23:07:05 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | | 4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. |
5 | * Copyright (c) 1994, 1995 Jochen Pohl | | 5 | * Copyright (c) 1994, 1995 Jochen Pohl |
6 | * All Rights Reserved. | | 6 | * All Rights Reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -28,27 +28,27 @@ | | | @@ -28,27 +28,27 @@ |
28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #if HAVE_NBTOOL_CONFIG_H | | 35 | #if HAVE_NBTOOL_CONFIG_H |
36 | #include "nbtool_config.h" | | 36 | #include "nbtool_config.h" |
37 | #endif | | 37 | #endif |
38 | | | 38 | |
39 | #include <sys/cdefs.h> | | 39 | #include <sys/cdefs.h> |
40 | #if defined(__RCSID) && !defined(lint) | | 40 | #if defined(__RCSID) && !defined(lint) |
41 | __RCSID("$NetBSD: decl.c,v 1.203 2021/07/15 22:47:17 rillig Exp $"); | | 41 | __RCSID("$NetBSD: decl.c,v 1.204 2021/07/15 23:07:05 rillig Exp $"); |
42 | #endif | | 42 | #endif |
43 | | | 43 | |
44 | #include <sys/param.h> | | 44 | #include <sys/param.h> |
45 | #include <limits.h> | | 45 | #include <limits.h> |
46 | #include <stdlib.h> | | 46 | #include <stdlib.h> |
47 | #include <string.h> | | 47 | #include <string.h> |
48 | | | 48 | |
49 | #include "lint1.h" | | 49 | #include "lint1.h" |
50 | | | 50 | |
51 | const char *unnamed = "<unnamed>"; | | 51 | const char *unnamed = "<unnamed>"; |
52 | | | 52 | |
53 | /* shared type structures for arithmetic types and void */ | | 53 | /* shared type structures for arithmetic types and void */ |
54 | static type_t *typetab; | | 54 | static type_t *typetab; |
| @@ -736,120 +736,125 @@ dcs_adjust_storage_class(void) | | | @@ -736,120 +736,125 @@ dcs_adjust_storage_class(void) |
736 | /* illegal storage class */ | | 736 | /* illegal storage class */ |
737 | error(8); | | 737 | error(8); |
738 | dcs->d_scl = NOSCL; | | 738 | dcs->d_scl = NOSCL; |
739 | } | | 739 | } |
740 | } else if (dcs->d_ctx == ARG || dcs->d_ctx == PROTO_ARG) { | | 740 | } else if (dcs->d_ctx == ARG || dcs->d_ctx == PROTO_ARG) { |
741 | if (dcs->d_scl != NOSCL && dcs->d_scl != REG) { | | 741 | if (dcs->d_scl != NOSCL && dcs->d_scl != REG) { |
742 | /* only register valid as formal parameter storage... */ | | 742 | /* only register valid as formal parameter storage... */ |
743 | error(9); | | 743 | error(9); |
744 | dcs->d_scl = NOSCL; | | 744 | dcs->d_scl = NOSCL; |
745 | } | | 745 | } |
746 | } | | 746 | } |
747 | } | | 747 | } |
748 | | | 748 | |
749 | /* | | 749 | /* Merge the declaration specifiers from dcs into dcs->d_type. */ |
750 | * Create a type structure from the information gathered in | | 750 | static void |
751 | * the declaration stack. | | 751 | dcs_merge_declaration_specifiers(void) |
752 | * Complain about storage classes which are not possible in current | | | |
753 | * context. | | | |
754 | */ | | | |
755 | void | | | |
756 | end_type(void) | | | |
757 | { | | 752 | { |
758 | tspec_t t, s, l, c; | | 753 | tspec_t t, s, l, c; |
759 | type_t *tp; | | 754 | type_t *tp; |
760 | | | 755 | |
761 | t = dcs->d_abstract_type; /* VOID, BOOL, CHAR, INT or COMPLEX */ | | 756 | t = dcs->d_abstract_type; /* VOID, BOOL, CHAR, INT or COMPLEX */ |
762 | c = dcs->d_complex_mod; /* FLOAT or DOUBLE */ | | 757 | c = dcs->d_complex_mod; /* FLOAT or DOUBLE */ |
763 | s = dcs->d_sign_mod; /* SIGNED or UNSIGN */ | | 758 | s = dcs->d_sign_mod; /* SIGNED or UNSIGN */ |
764 | l = dcs->d_rank_mod; /* SHORT, LONG or QUAD */ | | 759 | l = dcs->d_rank_mod; /* SHORT, LONG or QUAD */ |
765 | tp = dcs->d_type; | | 760 | tp = dcs->d_type; |
766 | | | 761 | |
767 | #ifdef DEBUG | | 762 | #ifdef DEBUG |
768 | printf("%s: %s\n", __func__, type_name(tp)); | | 763 | printf("%s: %s\n", __func__, type_name(tp)); |
769 | #endif | | 764 | #endif |
770 | if (t == NOTSPEC && s == NOTSPEC && l == NOTSPEC && c == NOTSPEC && | | 765 | if (t == NOTSPEC && s == NOTSPEC && l == NOTSPEC && c == NOTSPEC && |
771 | tp == NULL) | | 766 | tp == NULL) |
772 | dcs->d_notyp = true; | | 767 | dcs->d_notyp = true; |
773 | if (t == NOTSPEC && s == NOTSPEC && (l == NOTSPEC || l == LONG) && | | 768 | if (t == NOTSPEC && s == NOTSPEC && (l == NOTSPEC || l == LONG) && |
774 | tp == NULL) | | 769 | tp == NULL) |
775 | t = c; | | 770 | t = c; |
776 | | | 771 | |
777 | if (tp != NULL) { | | 772 | if (tp != NULL) { |
778 | lint_assert(t == NOTSPEC); | | 773 | lint_assert(t == NOTSPEC); |
779 | lint_assert(s == NOTSPEC); | | 774 | lint_assert(s == NOTSPEC); |
780 | lint_assert(l == NOTSPEC); | | 775 | lint_assert(l == NOTSPEC); |
| | | 776 | return; |
781 | } | | 777 | } |
782 | | | 778 | |
783 | if (tp == NULL) { | | 779 | switch (t) { |
784 | switch (t) { | | 780 | case BOOL: |
785 | case BOOL: | | 781 | break; |
786 | break; | | 782 | case NOTSPEC: |
787 | case NOTSPEC: | | 783 | t = INT; |
788 | t = INT; | | 784 | /* FALLTHROUGH */ |
789 | /* FALLTHROUGH */ | | 785 | case INT: |
790 | case INT: | | 786 | if (s == NOTSPEC) |
791 | if (s == NOTSPEC) | | 787 | s = SIGNED; |
792 | s = SIGNED; | | 788 | break; |
793 | break; | | 789 | case CHAR: |
794 | case CHAR: | | 790 | if (l != NOTSPEC) { |
795 | if (l != NOTSPEC) { | | 791 | dcs->d_terr = true; |
796 | dcs->d_terr = true; | | | |
797 | l = NOTSPEC; | | | |
798 | } | | | |
799 | break; | | | |
800 | case FLOAT: | | | |
801 | if (l == LONG) { | | | |
802 | l = NOTSPEC; | | | |
803 | t = DOUBLE; | | | |
804 | if (!tflag) | | | |
805 | /* use 'double' instead of 'long ... */ | | | |
806 | warning(6); | | | |
807 | } | | | |
808 | break; | | | |
809 | case DOUBLE: | | | |
810 | if (l != LONG) | | | |
811 | break; | | | |
812 | /* FALLTHROUGH */ | | | |
813 | case LDOUBLE: | | | |
814 | l = NOTSPEC; | | 792 | l = NOTSPEC; |
815 | t = LDOUBLE; | | | |
816 | if (tflag) | | | |
817 | /* 'long double' is illegal in ... */ | | | |
818 | warning(266); | | | |
819 | break; | | | |
820 | case DCOMPLEX: | | | |
821 | if (l == LONG) { | | | |
822 | l = NOTSPEC; | | | |
823 | t = LCOMPLEX; | | | |
824 | } | | | |
825 | break; | | | |
826 | case VOID: | | | |
827 | case FCOMPLEX: | | | |
828 | case LCOMPLEX: | | | |
829 | break; | | | |
830 | default: | | | |
831 | if (is_integer(t)) | | | |
832 | break; | | | |
833 | INTERNAL_ERROR("end_type(%s)", tspec_name(t)); | | | |
834 | } | | 793 | } |
835 | if (t != INT && t != CHAR && (s != NOTSPEC || l != NOTSPEC)) { | | 794 | break; |
836 | dcs->d_terr = true; | | 795 | case FLOAT: |
837 | l = s = NOTSPEC; | | 796 | if (l == LONG) { |
| | | 797 | l = NOTSPEC; |
| | | 798 | t = DOUBLE; |
| | | 799 | if (!tflag) |
| | | 800 | /* use 'double' instead of 'long float' */ |
| | | 801 | warning(6); |
838 | } | | 802 | } |
839 | if (l != NOTSPEC) | | 803 | break; |
840 | t = l; | | 804 | case DOUBLE: |
841 | dcs->d_type = gettyp(merge_type_specifiers(t, s)); | | 805 | if (l != LONG) |
| | | 806 | break; |
| | | 807 | /* FALLTHROUGH */ |
| | | 808 | case LDOUBLE: |
| | | 809 | l = NOTSPEC; |
| | | 810 | t = LDOUBLE; |
| | | 811 | if (tflag) |
| | | 812 | /* 'long double' is illegal in traditional C */ |
| | | 813 | warning(266); |
| | | 814 | break; |
| | | 815 | case DCOMPLEX: |
| | | 816 | if (l == LONG) { |
| | | 817 | l = NOTSPEC; |
| | | 818 | t = LCOMPLEX; |
| | | 819 | } |
| | | 820 | break; |
| | | 821 | case VOID: |
| | | 822 | case FCOMPLEX: |
| | | 823 | case LCOMPLEX: |
| | | 824 | break; |
| | | 825 | default: |
| | | 826 | lint_assert(is_integer(t)); |
| | | 827 | } |
| | | 828 | if (t != INT && t != CHAR && (s != NOTSPEC || l != NOTSPEC)) { |
| | | 829 | dcs->d_terr = true; |
| | | 830 | l = s = NOTSPEC; |
842 | } | | 831 | } |
| | | 832 | if (l != NOTSPEC) |
| | | 833 | t = l; |
| | | 834 | dcs->d_type = gettyp(merge_type_specifiers(t, s)); |
| | | 835 | } |
| | | 836 | |
| | | 837 | /* |
| | | 838 | * Create a type structure from the information gathered in |
| | | 839 | * the declaration stack. |
| | | 840 | * Complain about storage classes which are not possible in current |
| | | 841 | * context. |
| | | 842 | */ |
| | | 843 | void |
| | | 844 | end_type(void) |
| | | 845 | { |
| | | 846 | |
| | | 847 | dcs_merge_declaration_specifiers(); |
843 | | | 848 | |
844 | if (dcs->d_mscl) { | | 849 | if (dcs->d_mscl) { |
845 | /* only one storage class allowed */ | | 850 | /* only one storage class allowed */ |
846 | error(7); | | 851 | error(7); |
847 | } | | 852 | } |
848 | if (dcs->d_terr) { | | 853 | if (dcs->d_terr) { |
849 | /* illegal type combination */ | | 854 | /* illegal type combination */ |
850 | error(4); | | 855 | error(4); |
851 | } | | 856 | } |
852 | | | 857 | |
853 | dcs_adjust_storage_class(); | | 858 | dcs_adjust_storage_class(); |
854 | | | 859 | |
855 | if (dcs->d_const && dcs->d_type->t_const) { | | 860 | if (dcs->d_const && dcs->d_type->t_const) { |