<div dir="ltr"><div>Hey Wilhelm,</div><div><br></div><div>That's a bug, the "interrupt" attribute is not being recognized by the backend.<br></div><div><br></div><div>I have fixed it in <a href="https://github.com/llvm/llvm-project/commit/339b34266c1b54a9b5ff2f83cfb1da9cd8c9d90a">https://github.com/llvm/llvm-project/commit/339b34266c1b54a9b5ff2f83cfb1da9cd8c9d90a</a></div><div><br></div><div>Pull the latest LLVM and it should be fixed.<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 31, 2020 at 8:00 AM Wilhelm Meier <<a href="mailto:wilhelm.meier@hs-kl.de">wilhelm.meier@hs-kl.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Dylan,<br>
<br>
I used the following commandline:<br>
<br>
clang++ -Os -DF_OSC=20000000 -DF_CPU=20000000 --target=avr -I.<br>
-I../include0 -I../../include0 -I../../../include0 -I../../include0/std<br>
-I../include0/std -I../../../include0/std -I../../3rdparty/boost<br>
-I/usr/avr/include -mmcu=atmega328p<br>
/home/lmeier/Projekte/wmucpp/clang/bm00/bm00.cc -S -emit-llvm --output<br>
<a href="http://bm00.ir" rel="noreferrer" target="_blank">bm00.ir</a><br>
<br>
Please find the IR attached in the file <a href="http://bm00.ir" rel="noreferrer" target="_blank">bm00.ir</a><br>
<br>
Thanks,<br>
Wilhelm<br>
<br>
<br>
Am 30.03.20 um 13:44 schrieb Dylan McKay:<br>
> Hey Wilhelm,<br>
> <br>
> Could you post the LLVM IR generated from your C++ file?<br>
> <br>
> This can be achieved with 'clang -S -emit-llvm'<br>
> <br>
> Cheers<br>
> <br>
> On Sat, Mar 28, 2020 at 6:36 PM Wilhelm Meier <<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a><br>
> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>>> wrote:<br>
> <br>
> Answering partly to myself there was a extern "C" missing.<br>
> <br>
> But the register pushes ans reti are still missing.<br>
> <br>
> Whats wrong?<br>
> <br>
> Am 28.03.20 um 06:26 schrieb Wilhelm Meier via llvm-dev:<br>
> > Hi Dylan,<br>
> ><br>
> > the following code<br>
> ><br>
> > volatile uint8_t v1;<br>
> > volatile uint8_t v2;<br>
> ><br>
> > __attribute__((interrupt)) void __vector_21(void) {<br>
> > v2 = v1;<br>
> > }<br>
> ><br>
> > produces in C mode:<br>
> ><br>
> > 00000092 <__vector_21>:<br>
> > 92: 80 91 61 00 lds r24, 0x0061 ; 0x800061 <v1><br>
> > 96: 80 93 60 00 sts 0x0060, r24 ; 0x800060 <__data_end><br>
> > 9a: 08 95 ret<br>
> ><br>
> > and in C++ mode:<br>
> ><br>
> > 00000074 <_Z11__vector_21v>:<br>
> > 74: 80 91 60 00 lds r24, 0x0060 ; 0x800060 <__data_end><br>
> > 78: 80 93 61 00 sts 0x0061, r24 ; 0x800061 <v2><br>
> > 7c: 08 95 ret<br>
> ><br>
> > So, in C++ mode it is not recognized as ISR due to name mangling.<br>
> ><br>
> > Furthermore there are no register push/pos and no reti.<br>
> ><br>
> > Whats wrong?<br>
> ><br>
> > Thanks.<br>
> ><br>
> ><br>
> > Am 11.03.20 um 08:13 schrieb Dylan McKay:<br>
> >> Here you go Wilhelm,<br>
> >><br>
> >> <a href="https://github.com/dylanmckay/clang-avr-libc-interrupt-example" rel="noreferrer" target="_blank">https://github.com/dylanmckay/clang-avr-libc-interrupt-example</a><br>
> >><br>
> >><br>
> >><br>
> >> On Thu, Mar 5, 2020 at 4:05 AM Wilhelm Meier<br>
> <<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>><br>
> >> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a> <mailto:<a href="mailto:wilhelm.meier@hs-kl.de" target="_blank">wilhelm.meier@hs-kl.de</a>>>><br>
> wrote:<br>
> >><br>
> >> Am 04.03.20 um 13:28 schrieb Dylan McKay:<br>
> >><br>
> >> ><br>
> >> > * *The C/C++ function needs to be declared with either<br>
> the calling<br>
> >> > convention avr-interrupt or<br>
> avr-non-blocking-interrupt.* Skipping<br>
> >> > this step will cause regular ret instructions to be<br>
> emitted for<br>
> >> > return-from-subroutine, instead of the required reti<br>
> for interrupt<br>
> >> > handlers. ISRs also have stricter requirements on which<br>
> registers<br>
> >> > must not be clobbered after execution, which the<br>
> backend will<br>
> >> handle<br>
> >> > properly by restoring all clobbered registers in the<br>
> interrupt<br>
> >> > handler epilogue<br>
> >> > * *The symbol names of the ISR function handlers must<br>
> match those<br>
> >> > referred to in avr-libc/avr-libgcc/crt*. This is<br>
> because the ISR<br>
> >> > table is specified in assembly inside the GCC AVR CRT.<br>
> The way it<br>
> >> > works is that the external symbol references in the CRT<br>
> object<br>
> >> files<br>
> >> > are declared with an exotic linkage type that causes<br>
> the linker to<br>
> >> > skip linking of the symbols if they are undefined<br>
> references.<br>
> >> If you<br>
> >> > chose a custom ISR table in a custom CRT or runtime<br>
> library, you<br>
> >> > would be free to choose ISR names as you pleased.<br>
> >> ><br>
> >> Thank you for your explanation. But I suspect I didn't get it<br>
> right. Can<br>
> >> you please provide an example?<br>
> >><br>
> >> Thanks<br>
> >><br>
> > _______________________________________________<br>
> > LLVM Developers mailing list<br>
> > <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
> > <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
> ><br>
> <br>
</blockquote></div>