This patch makes sure annotation attributes are emitted for declarations. It does this by applying two changes.
First, AddGlobalAnnotations is called from SetFunctionAttributes instead of from EmitGlobalFunctionDefinition. This makes sure these annotations are emitted for declarations but makes code like the following crash:
__attribute__((annotate("foo"))) void foo(); void bar(){foo();} void foo() {}
I will try to explain what I think happens when this code is compiled:
- A declaration is created for a function foo having an unspecified number of arguments. This declaration is not emitted but queued for deferred emission. My patch did create an annotation referring to this declaration, though.
- The call site triggers emission of the declaration of foo.
- Now foo has zero arguments and the original declaration is replaced by a new function. Since the added annotation still refers to the deleted declaration, this causes a crash.
Therefore, my patch also changes AddGlobalAnnotations to not create the annotation right away. Instead, annotations are created in EmitGlobalAnnotations.