Skip to content

wrong weak alias optimization with llvm-gcc-4.2 #2050

@llvmbot

Description

@llvmbot
Bugzilla Link 1678
Resolution FIXED
Resolved on Sep 03, 2008 02:26
Version unspecified
OS Linux
Depends On llvm/llvm-bugzilla-archive#2742
Reporter LLVM Bugzilla Contributor
CC @nlewycky

Extended Description

This bug only effects llvm-gcc-4.2. Here is the testcase:

extern void B (void);
static __typeof(B) A attribute ((weakref("B")));
int active (void)
{
static void *const p = extension (void *) &A;
return p != 0;
}

This is optimized to:

@​A = alias weak void ()* @​B
define i32 @​active() {
entry:
ret i32 1
}

which is wrong (see #2018 ). The cause is quite interesting though:
llvm-gcc emits the function @​active and runs per function passes on
it. At that point A has not yet been declared an alias for B! It
is simply an ordinary global. Thus the optimizers correctly decide
that &A is not null. The alias is only output later.

This shows a danger with per-function passes: if a function refers
to globals then those globals had better be in their final state
before any passes are run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzilla

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions