[PATCH, Darwin] Use switch_to_section () in darwin_file_end.
One I’ve had hanging around in my local trees for a long time. We have been emitting two section switches in the Darwin's file end function by outputting the asm directly. This means that varasm’s tracking of the section switched is not updated which could matter if we elect to reorder some of the file end operations in support of LTO actions. tested on powerpc-darwin9, x86_64-darwin18 applied to mainline Iain gcc/ 2019-05-18 Iain Sandoe * config/darwin.c (darwin_file_end): Use switch_to_section () instead of direct output of the asm. diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index f62f1c7..17e1801 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -2939,12 +2939,10 @@ darwin_file_end (void) if (flag_objc_abi >= 2) { flags = 16; - output_section_asm_op - (darwin_sections[objc2_image_info_section]->unnamed.data); + switch_to_section (darwin_sections[objc2_image_info_section]); } else - output_section_asm_op - (darwin_sections[objc_image_info_section]->unnamed.data); + switch_to_section (darwin_sections[objc_image_info_section]); ASM_OUTPUT_ALIGN (asm_out_file, 2); fputs ("L_OBJC_ImageInfo:\n", asm_out_file);
[PATCH, Objective-c] Add 'instancetype' typedef alias.
Small part of catching up with changes made to the objective-c language. The instancetype has been added to other objective-c implementations as a typedef alias to id in order to allow diagnosis of cases where a class is used or returned where an instance is expected. This adds the typedef, and tests that we can parse it. It doesn't alter the diagnostics yet. tested on x86_64-darwin16, x86_64-linux-gnu applied to mainline Iain gcc/objc/ 2019-05-18 Iain Sandoe * objc/objc-act.h (OCTI_INSTANCE_TYPE, OCTI_INSTANCETYPE_NAME): New. (objc_global_trees): Add instance type and name. (INSTANCE_TYPEDEF_NAME): New. * objc/objc-act.c (synth_module_prologue): Build decls for objc_instancetype_type and objc_instancetype_name. gcc/testsuite/ 2019-05-18 Iain Sandoe * objc.dg/instancetype-0.m: New. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 7ee3306..2173092 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -2950,12 +2950,14 @@ synth_module_prologue (void) objc_class_reference = xref_tag (RECORD_TYPE, objc_class_id); objc_object_type = build_pointer_type (objc_object_reference); + objc_instancetype_type = build_pointer_type (objc_object_reference); objc_class_type = build_pointer_type (objc_class_reference); objc_object_name = get_identifier (OBJECT_TYPEDEF_NAME); + objc_instancetype_name = get_identifier (INSTANCE_TYPEDEF_NAME); objc_class_name = get_identifier (CLASS_TYPEDEF_NAME); - /* Declare the 'id' and 'Class' typedefs. */ + /* Declare the 'id', 'instancetype' and 'Class' typedefs. */ type = lang_hooks.decls.pushdecl (build_decl (input_location, TYPE_DECL, objc_object_name, @@ -2964,6 +2966,12 @@ synth_module_prologue (void) type = lang_hooks.decls.pushdecl (build_decl (input_location, TYPE_DECL, + objc_instancetype_name, + objc_instancetype_type)); + TREE_NO_WARNING (type) = 1; + + type = lang_hooks.decls.pushdecl (build_decl (input_location, + TYPE_DECL, objc_class_name, objc_class_type)); TREE_NO_WARNING (type) = 1; diff --git a/gcc/objc/objc-act.h b/gcc/objc/objc-act.h index 5794cdf..3b69043 100644 --- a/gcc/objc/objc-act.h +++ b/gcc/objc/objc-act.h @@ -313,6 +313,7 @@ enum objc_tree_index OCTI_SUPER_TYPE, OCTI_SEL_TYPE, OCTI_ID_TYPE, +OCTI_INSTANCE_TYPE, OCTI_CLS_TYPE, OCTI_NST_TYPE, OCTI_PROTO_TYPE, @@ -368,6 +369,7 @@ enum objc_tree_index OCTI_OBJ_ID, OCTI_CLS_ID, OCTI_ID_NAME, +OCTI_INSTANCETYPE_NAME, OCTI_CLASS_NAME, OCTI_CNST_STR_ID, OCTI_CNST_STR_TYPE, @@ -443,6 +445,7 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX]; #define objc_super_typeobjc_global_trees[OCTI_SUPER_TYPE] #define objc_selector_type objc_global_trees[OCTI_SEL_TYPE] #define objc_object_type objc_global_trees[OCTI_ID_TYPE] +#define objc_instancetype_type objc_global_trees[OCTI_INSTANCE_TYPE] #define objc_class_typeobjc_global_trees[OCTI_CLS_TYPE] #define objc_instance_type objc_global_trees[OCTI_NST_TYPE] #define objc_protocol_type objc_global_trees[OCTI_PROTO_TYPE] @@ -570,7 +573,8 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX]; #define objc_object_id objc_global_trees[OCTI_OBJ_ID] #define objc_class_id objc_global_trees[OCTI_CLS_ID] -#define objc_object_name objc_global_trees[OCTI_ID_NAME] +#define objc_object_nameobjc_global_trees[OCTI_ID_NAME] +#define objc_instancetype_name objc_global_trees[OCTI_INSTANCETYPE_NAME] #define objc_class_nameobjc_global_trees[OCTI_CLASS_NAME] /* Constant string classes. */ @@ -608,6 +612,7 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX]; /* Reserved tag definitions. */ #define OBJECT_TYPEDEF_NAME"id" +#define INSTANCE_TYPEDEF_NAME "instancetype" #define CLASS_TYPEDEF_NAME "Class" #define TAG_OBJECT "objc_object" diff --git a/gcc/testsuite/objc.dg/instancetype-0.m b/gcc/testsuite/objc.dg/instancetype-0.m new file mode 100644 index 000..60e086a --- /dev/null +++ b/gcc/testsuite/objc.dg/instancetype-0.m @@ -0,0 +1,30 @@ +/* Contributed by Iain Sandoe , December 2014. */ +/* { dg-do compile } */ + +/* Basic check of parsing instancetype. */ + +extern id class_createInstance (id, int); +extern id class_getSuperclass (id); + +@interface MyObject +{ + Class isa; +} ++ (instancetype)alloc; +- (instancetype)init; ++ (instancetype)initialize; ++ (instancetype)factoryMethodA; ++ (id)factoryMethodB; ++ (Class) class; ++ (Class) superclass; +@end
[PATCH, Darwin, objective-c] Register gnu-runtime headers correctly.
Darwin is able to use two runtimes for objective-c; the default is its native "NeXT" runtime, but also it can build code using the "gnu-runtime". In order to do this, we have to be able to find the gnu-runtime headers (which are installed into the compiler's tree). The process to do this has been erroneously prepending the sysroot to this when a sysroot is in force. The gnu-runtime headers have never been installed in a Darwin (macOS) SDK so we must make sure that they are found local to the compiler. tested on powerpc-darwin9, x86_64-darwin16 applied to mainline Iain gcc/ 2019-05-18 Iain Sandoe * config/darwin-c.c (darwin_register_objc_includes): Do not prepend the sysroot when building gnu-runtime header search paths. diff --git a/gcc/config/darwin-c.c b/gcc/config/darwin-c.c index 8331153..aa5d2f2 100644 --- a/gcc/config/darwin-c.c +++ b/gcc/config/darwin-c.c @@ -463,41 +463,32 @@ static const char *framework_defaults [] = /* Register the GNU objective-C runtime include path if STDINC. */ void -darwin_register_objc_includes (const char *sysroot, const char *iprefix, - int stdinc) +darwin_register_objc_includes (const char *sysroot ATTRIBUTE_UNUSED, + const char *iprefix, int stdinc) { - const char *fname; - size_t len; - /* We do not do anything if we do not want the standard includes. */ - if (!stdinc) -return; - - fname = GCC_INCLUDE_DIR "-gnu-runtime"; - - /* Register the GNU OBJC runtime include path if we are compiling OBJC -with GNU-runtime. */ + /* If we want standard includes; Register the GNU OBJC runtime include + path if we are compiling OBJC with GNU-runtime. + This path is compiler-relative, we don't want to prepend the sysroot + since it's not expected to find the headers there. */ - if (c_dialect_objc () && !flag_next_runtime) + if (stdinc && c_dialect_objc () && !flag_next_runtime) { + const char *fname = GCC_INCLUDE_DIR "-gnu-runtime"; char *str; - /* See if our directory starts with the standard prefix. + size_t len; + + /* See if our directory starts with the standard prefix. "Translate" them, i.e. replace /usr/local/lib/gcc... with IPREFIX and search them first. */ - if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0 && !sysroot + if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0 && !strncmp (fname, cpp_GCC_INCLUDE_DIR, len)) { str = concat (iprefix, fname + len, NULL); - /* FIXME: wrap the headers for C++awareness. */ - add_path (str, INC_SYSTEM, /*c++aware=*/false, false); + add_path (str, INC_SYSTEM, /*c++aware=*/true, false); } - /* Should this directory start with the sysroot? */ - if (sysroot) - str = concat (sysroot, fname, NULL); - else - str = update_path (fname, ""); - - add_path (str, INC_SYSTEM, /*c++aware=*/false, false); + str = update_path (fname, ""); + add_path (str, INC_SYSTEM, /*c++aware=*/true, false); } }
Re: [PATCH] Add workaround for broken C/C++ wrappers to LAPACK (PR fortran/90329)
Hi Jakub, Could we easily detect at resolve time whether a subroutine/function makes any implicitly prototyped calls and limit this workaround to those cases (i.e. only old-style Fortran)? I've mentioned it in the PR, but not sure how exactly to check that. I think we could to that. We could look at all the external symbols and check with if (sym->attr.if_src == IFSRC_UNKNOWN) . Let me think about this some more... Regards Thomas
Re: malloc cannot alias preexisting pointers
On Wed, 15 May 2019, Richard Biener wrote: As you write the heuristic you could as well remove the malloc result points-to set from the others after points-to analysis is finished? Looking at the vector testcase: #include #include #include inline void* operator new(std::size_t n){return malloc(n);} inline void operator delete(void*p){free(p);} typedef std::unique_ptr T; typedef std::vector V; void f(V&v){v.reserve(1024);} I get in the alias pass for malloc _24, points-to NULL, points-to vars: { D.48250 } (escaped, escaped heap) and for the pointer I want to say cannot alias _24 _4, points-to non-local, points-to escaped, points-to NULL, points-to vars: { } I don't see what I can remove from where, all the important info is in "escaped" (well in this case I guess "points-to escaped" could be dropped because this is the very first statement and nothing has escaped yet, but that's too specialized). Actually, I don't even understand how I could encode the fact that they cannot alias in the current points-to structures. It seems that it would require at least changing from one "escaped" to several "escaped_XX" (or more radically several PT info per SSA_NAME). One could even devise something like a "negative" live set (all-locals & ~live-locals), pruning the points-to sets of SSA names on the whole CFG considering that int *p; int y; void foo() { int x; *p = &y; if (p != &y) abort (); *p = &x; } computes p to point to both y and x at the point of the comparison. That is, this isn't special to malloc but to all variables that come into scope only after function entry. Indeed, flow sensitivity can help for more than malloc. This is something I would like much more than these kinds of local tricks in the oracle itself. That's interesting, but I don't see how it would solve the "escaped" issue. One detail I noticed: in the alias dump, I see _10 = { ESCAPED NONLOCAL } for a POINTER_DIFF_EXPR that cannot encode a pointer. If I change that to get _10 = { } and _6 = { }, for _19 = (long unsigned int) _10; I have _19 = { } as expected, but for _7 = _6 /[ex] 8; I get _7 = { NONLOCAL } same as v where I was expecting _7 = { }. I guess that's because it involves a constant, and constants can be addresses. It feels like the pass is creating a bit of useless work for itself, though that probably doesn't matter... -- Marc Glisse
Re: [PATCH] Remove empty loop with assumed finiteness (PR tree-optimization/89713)
(@Feng Xue, it is better to include testcases in your patches) I'm not a big fan of this patch. I'd rather be looking at either improving our analysis Better analysis cannot hurt. or adding attributes to the loops to help the analysis bits prove termination. There may not be a loop in the source code, it may be a recursive function call that gcc turned into a loop. Plus, I know that it applies to all loops in my program. We could have a function to compute the length of a linked list: struct A { A*p; }; unsigned l(A*a){return a?l(a->p)+1:0;} and because of other optimizations, it turns out that we do not actually use this length void g(A*a){l(a);} wouldn't it be nice if gcc could remove all that useless code, instead of keeping a useless loop on the off chance that it might be infinite? And we had sth similar in the past and ended up removing it. -funsafe-loop-optimizations IIRC. IIUC that was slightly different: "This option tells the loop optimizer to assume that loop indices do not overflow, and that loops with nontrivial exit condition are not infinite." The assumption on indices looks unsafe indeed if it applied to unsigned indices in non-empty loops. But the C++ standard went to the trouble of banning infinite loops without side effects specifically to enable DCE on this type of code... Actually, an infinite loop with a trivial exit condition looks like a great opportunity to use __builtin_unreachable() to me ;-) (I have been wanting a -fmain-does-return -fno-funny-business for years, since I looked at replacing some malloc with stack allocations, but that's all out of scope for this patch) Why exactly are we trying so hard to preserve no-side-effect, infinite loops? What are they good for? Note that reading an atomic or volatile variable counts as a side effect for this purpose. It looks like some kind of busy waiting, but without checking a flag, so it can only be stopped by some external action (say a signal), so if the OS has any notion of sleep for a thread, blocking would be better. Or maybe it is running through a circular list, ensuring that it stays in RAM? Anyway it seems specific enough that that strange code should be the one needing an annotation. -- Marc Glisse
[patch, fortran] Put workaround for broken C/Lapack wrappers behind flag
Hello world, the attached patch puts the workaround introduced by Jakub behind a flag. I debated with myself what the name should be. -fbroken-c-interfaces-die-die-die came to mind, but that would have penalized people who wanted to disable the option :-) Therefore, I have settled on -fbroken-callers and -fno-broken-callers, respectively. If somebody has a better idea, please let the list know. What we should do with this flag for gcc-10 is still up for discussion, if we make it the default or not. Regression-tested. "make info", "make dvi" and "make pdf" all passed. OK for trunk? Regards Thomas 2019-05-18 Thomas Koenig PR fortran/90329 * invoke.texi: Document -fbroken-callers. * lang.opt: Add -fbroken-callers. * trans-decl.c (create_function_arglist): Only set DECL_HIDDEN_STRING_LENGTH if flag_broken_callers is set. Index: invoke.texi === --- invoke.texi (Revision 271371) +++ invoke.texi (Arbeitskopie) @@ -181,7 +181,7 @@ and warnings}. @item Code Generation Options @xref{Code Gen Options,,Options for code generation conventions}. @gccoptlist{-faggressive-function-elimination -fblas-matmul-limit=@var{n} @gol --fbounds-check -fcheck-array-temporaries @gol +-fbounds-check -fbroken-callers -fcheck-array-temporaries @gol -fcheck=@var{} @gol -fcoarray=@var{} -fexternal-blas -ff2c -ffrontend-loop-interchange @gol @@ -1617,6 +1617,30 @@ warnings for generated array temporaries. @c Note: This option is also referred in gcc's manpage Deprecated alias for @option{-fcheck=bounds}. +@item -fbroken-callers +@opindex @code{broken-callers} +Some C interfaces to Fortran codes violate the gfortran ABI by +omitting the hidden character length arguments as described in +@xref{Argument passing conventions}. This can lead to crashes +because pushing arguments for tail calls can overflow the stack. + +To provide a workaround for existing binary packages, this option +disables tail call optimization for gfortran procedures with character +arguments. + +Using this option can lead to problems including crashes due to +insufficient stack space. + +It is @emph{very strongly} recommended to fix the code in question. +Support for this option will likely be withdrawn in a future release +of gfortran. + +The negative form, @option{-fno-broken-callers}, can be used to +disable this option. + +Default is currently @option{-fbroken-callers}, this will change +in future releases. + @item -fcheck-array-temporaries @opindex @code{fcheck-array-temporaries} Deprecated alias for @option{-fcheck=array-temps}. Index: lang.opt === --- lang.opt (Revision 271371) +++ lang.opt (Arbeitskopie) @@ -397,6 +397,10 @@ fblas-matmul-limit= Fortran RejectNegative Joined UInteger Var(flag_blas_matmul_limit) Init(30) -fblas-matmul-limit= Size of the smallest matrix for which matmul will use BLAS. +fbroken-callers +Fortran Var(flag_broken_callers) Init(1) +Disallow tail call optimization when a calling routine may have omitted character lenghts. + fcheck-array-temporaries Fortran Produce a warning at runtime if a array temporary has been created for a procedure argument. Index: trans-decl.c === --- trans-decl.c (Revision 271371) +++ trans-decl.c (Arbeitskopie) @@ -2516,7 +2516,11 @@ create_function_arglist (gfc_symbol * sym) DECL_ARG_TYPE (length) = len_type; TREE_READONLY (length) = 1; gfc_finish_decl (length); - if (f->sym->ts.u.cl + + /* Marking the length DECL_HIDDEN_STRING_LENGTH will lead + to tail calls being disabled. Only do that if we + potentially have broken callers. */ + if (flag_broken_callers && f->sym->ts.u.cl && f->sym->ts.u.cl->length && f->sym->ts.u.cl->length->expr_type == EXPR_CONSTANT) DECL_HIDDEN_STRING_LENGTH (length) = 1;
*ping* [patch, fortran] Inline argument packing
Am 11.05.19 um 15:10 schrieb Thomas Koenig: Hello world, this new version of the inlie argument packing patch (PR 88821) avoids the ICE on the test case for PR 61968. Otherwise it is unchanged. Regression-tested. OK for trunk? Ping?
[Patch, fortran] PR90498 - [8/9/10 Regression] ICE with select type/associate and derived type argument containing class(*)
This turns out to be obvious. The component of the dummy argument cannot be replaced by the hidden descriptor (actually the class object) and so an ICE occurs. The fix is to add a guard against the expression being a COMPONENT_REF. I will commit to all three branches tomorrow unless there are any objections. Bootstrapped and regtested on FC29/x86_64 Paul 2019-05-18 Paul Thomas PR fortran/90948 * trans-stmt.c (trans_associate_var) Do not use the saved descriptor if the expression is a COMPONENT_REF. 2019-05-18 Paul Thomas PR fortran/90948 * gfortran.dg/associate_48.f90 : New test. Index: gcc/fortran/trans-stmt.c === *** gcc/fortran/trans-stmt.c (revision 271056) --- gcc/fortran/trans-stmt.c (working copy) *** trans_associate_var (gfc_symbol *sym, gf *** 1858,1864 { if (e->symtree && DECL_LANG_SPECIFIC (e->symtree->n.sym->backend_decl) ! && GFC_DECL_SAVED_DESCRIPTOR (e->symtree->n.sym->backend_decl)) /* Use the original class descriptor stored in the saved descriptor to get the target_expr. */ target_expr = --- 1858,1865 { if (e->symtree && DECL_LANG_SPECIFIC (e->symtree->n.sym->backend_decl) ! && GFC_DECL_SAVED_DESCRIPTOR (e->symtree->n.sym->backend_decl) ! && TREE_CODE (target_expr) != COMPONENT_REF) /* Use the original class descriptor stored in the saved descriptor to get the target_expr. */ target_expr = Index: gcc/testsuite/gfortran.dg/associate_48.f90 === *** gcc/testsuite/gfortran.dg/associate_48.f90 (nonexistent) --- gcc/testsuite/gfortran.dg/associate_48.f90 (working copy) *** *** 0 --- 1,41 + ! { dg=do run } + ! + ! Test the fix for PR90498. + ! + ! Contributed by Vladimir Fuka + ! + type field_names_a + class(*), pointer :: var(:) =>null() + end type + + type(field_names_a),pointer :: a(:) + allocate (a(2)) + + allocate (a(1)%var(2), source = ["hello"," vlad"]) + allocate (a(2)%var(2), source = ["HELLO"," VLAD"]) + call s(a) + deallocate (a(1)%var) + deallocate (a(2)%var) + deallocate (a) + contains + subroutine s(a) + + type(field_names_a) :: a(:) + + select type (var => a(1)%var) + type is (character(*)) + if (any (var .ne. ["hello"," vlad"])) stop 1 + class default + stop + end select + + associate (var => a(2)%var) + select type (var) + type is (character(*)) + if (any (var .ne. ["HELLO"," VLAD"])) stop 2 + class default + stop + end select + end associate + end + end
Re: *ping* [patch, fortran] Inline argument packing
On Sat, May 18, 2019 at 09:15:00PM +0200, Thomas Koenig wrote: > Am 11.05.19 um 15:10 schrieb Thomas Koenig: > > Hello world, > > > > this new version of the inlie argument packing patch (PR 88821) > > avoids the ICE on the test case for PR 61968. Otherwise it is > > unchanged. > > > > Regression-tested. OK for trunk? > > Ping? OK. -- Steve
Re: [patch, fortran] Put workaround for broken C/Lapack wrappers behind flag
On Sat, May 18, 2019 at 08:37:06PM +0200, Thomas Koenig wrote: > > the attached patch puts the workaround introduced by Jakub behind > a flag. I debated with myself what the name should be. > -fbroken-c-interfaces-die-die-die came to mind, but that would > have penalized people who wanted to disable the option :-) > Therefore, I have settled on -fbroken-callers and -fno-broken-callers, > respectively. If somebody has a better idea, please let the list know. > > What we should do with this flag for gcc-10 is still up for discussion, > if we make it the default or not. > > Regression-tested. "make info", "make dvi" and "make pdf" all > passed. OK for trunk? > Looks good to me. I wonder if we should add a reference to the option that can produce C prototypes for a Fortran procedure in the description of -fbroken-caller. -- Steve
Re: [PATCH] Add workaround for broken C/C++ wrappers to LAPACK (PR fortran/90329)
On 5/17/19 12:33 PM, Janne Blomqvist wrote: --- snip --- And yes, while I think one year might be a quite optimistic timeframe to get this fixed, I agree we shouldn't keep the workaround indefinitely either. I think the best way would be if CBLAS & LAPACKE would be fixed, and then we could tell people to use those rather than their own in-house broken interfaces. Thankyou for clarifying, so the real bug here is in CBLAS and LAPACK? Gads! Cheers, Jerry
Re: New .md construct: define_insn_and_rewrite
On Tue, 14 May 2019, Richard Sandiford wrote: > Several SVE patterns need define_insn_and_splits that generate the > same insn_code, but with different operands. That's probably a > niche requirement, but it's cropping up often enough on the ACLE > branch that I think it would be good to have a syntactic sugar for it. > > This patch therefore adds a new construct called define_insn_and_rewrite. > It's basically a define_insn_and_split with an implicit split pattern, > obtained by copying the insn pattern and replacing match_operands with > match_dups and match_operators with match_op_dups. I think that sentence should be in the documentation, in one of the introductory sentences. > Any comments? > Suggestions for better names? I'll pass on this, for now. ;-) But, IMHO it lacks an allusion to define_insn_and_split. > Index: gcc/doc/md.texi > +@end smallexample Can you please add the equivalent define_insn_and_split "expansion" to the example? It'd help understanding the concept graphically at a glance. brgds, H-P