- BugFix: make_function_1_type_variadic() must hash the type itself, NOT
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 7 Apr 2009 12:04:51 +0000 (12:04 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 7 Apr 2009 12:04:51 +0000 (12:04 +0000)
  modify another one
- BugFix: r25810: only functions can have a prototype
- add a prototyped filed to function types
- K&R functions having a prototype are NOT variadic: this fixes
  fehler166.c

[r25813]

ast2firm.c
parser.c
type_t.h

index accf196..e3240ee 100644 (file)
@@ -380,7 +380,8 @@ static ir_type *create_method_type(const function_type_t *function_type, bool fo
                ++n;
        }
 
-       if (function_type->variadic || function_type->unspecified_parameters) {
+       if (function_type->variadic ||
+           (function_type->unspecified_parameters && !function_type->prototyped)) {
                set_method_variadicity(irtype, variadicity_variadic);
        }
 
index 0788db0..8309d4c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -4386,11 +4386,21 @@ static entity_t *record_entity(entity_t *entity, const bool is_definition)
                                                &previous_entity->base.source_position);
                        } else {
                                unsigned old_storage_class = prev_decl->storage_class;
+                               bool     kr_prototype      = false;
+
+                               if (is_type_function(type)) {
+                                       /* check if we have a prototype */
+                                       if (!prev_type->function.unspecified_parameters) {
+                                               type->function.prototyped = true;
+                                               if (type->function.kr_style_parameters)
+                                                       kr_prototype = true;
+                                       }
+                               }
                                if (warning.redundant_decls               &&
                                                is_definition                     &&
+                                               !kr_prototype                     &&
                                                !prev_decl->used                  &&
                                                !(prev_decl->modifiers & DM_USED) &&
-                                               !type->function.kr_style_parameters &&
                                                prev_decl->storage_class == STORAGE_CLASS_STATIC) {
                                        warningf(&previous_entity->base.source_position,
                                                        "unnecessary static forward declaration for '%#T'",
@@ -6285,11 +6295,23 @@ static type_t *make_function_1_type(type_t *return_type, type_t *argument_type)
        return identify_new_type(type);
 }
 
+/**
+ * Creates a return_type (func)(argument_type, ...) function type if not
+ * already exists.
+ *
+ * @param return_type    the return type
+ * @param argument_type  the argument type
+ */
 static type_t *make_function_1_type_variadic(type_t *return_type, type_t *argument_type)
 {
-       type_t *res = make_function_1_type(return_type, argument_type);
-       res->function.variadic = 1;
-       return res;
+       function_parameter_t *const parameter = allocate_parameter(argument_type);
+
+       type_t *type               = allocate_type_zero(TYPE_FUNCTION);
+       type->function.return_type = return_type;
+       type->function.parameters  = parameter;
+       type->function.variadic    = true;
+
+       return identify_new_type(type);
 }
 
 /**
index 5c703c7..a9b247d 100644 (file)
--- a/type_t.h
+++ b/type_t.h
@@ -144,6 +144,7 @@ struct function_type_t {
        bool                  variadic : 1;
        bool                  unspecified_parameters : 1;
        bool                  kr_style_parameters : 1;
+       bool                  prototyped : 1;
 };
 
 struct compound_type_t {