https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113723

            Bug ID: 113723
           Summary: -freorder-blocks-and-partition emits bogus asm
                    directives on aarch64
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redbeard0531 at gmail dot com
  Target Milestone: ---

It tries to subtract labels across the function split which the assembler
rejects. At the very least it does this when generating a switch jump table,
but there may be other cases.

https://www.godbolt.org/z/Ynh1zzY4a

Repro with -O3 -freorder-blocks-and-partition:


[[gnu::cold]]void cold();

template<int i> void f();
#define GENERATE_CASE case __COUNTER__: f<__COUNTER__>(); break 

void test(int i) {
    switch(i) {
        case 1: cold(); break;
        GENERATE_CASE;
        GENERATE_CASE;
        GENERATE_CASE;
        GENERATE_CASE;
        GENERATE_CASE;
        GENERATE_CASE;
        GENERATE_CASE;
        GENERATE_CASE;
        GENERATE_CASE;
        GENERATE_CASE;
    }
}

test(int):
        cmp     w0, 18
        bls     .L17
.L1:
        ret
.L17:
        adrp    x1, .L4
        add     x1, x1, :lo12:.L4
        ldrb    w1, [x1,w0,uxtw]
        adr     x0, .Lrtx4
        add     x1, x0, w1, sxtb #2
        br      x1
.Lrtx4:
.L4:
        .byte   (.L14 - .Lrtx4) / 4
        .byte   (.L13 - .Lrtx4) / 4 // <<<< THIS IS THE BAD ONE
        .byte   (.L12 - .Lrtx4) / 4

...

test(int) [clone .cold]:
.L13:
        b       cold()


/tmp/cck05x4u.s: Assembler messages:
/tmp/cck05x4u.s:48: Error: invalid operands (.text.unlikely and .text sections)
for `-'
Compiler returned: 1

I've repro'd on 11,12, and trunk.

Reply via email to