[Flang] Could you quickly add hexademical literals support?

Hi @sscalpone ! Thank you for all your hard work on Flang.

I’m wondering is it possible to quickly add hexademical literals support to Flang, such as z'0ff' ? Or could you guide me how to add it?

Kind regards,
Dmitry.

Hi Dmitry,

Thank you for the kind words.

Here’s what I see today:

integer :: j
j = z'0ff'
print *, j
end
% flang boz.f90
error: loc("/home/sscalpone/tmp/boz.f90":2:1): /proj/build/llvm/Linux_x86_64/flang/lib/Lower/ConvertExpr.cpp:869: not yet implemented: BOZ
LLVM ERROR: aborting

I’ll bet @psteinfeld can give you some tips to get you started. Good luck & have fun!

  • Steve
1 Like

BOZ literals in DATA statements and declaration initializers should work for you without further lowering support (e.g. integer, parameter :: j3 = z'666'). Since BOZ literals are of course constants, you can also wrap them in calls to intrinsic functions int, real, &c. and those will be folded to typed values before lowering. If you can share an actual code snippet with your usage of a BOZ literal that is failing, I can help you with a code edit that should make it work. Be advised, we intentionally don’t support BOZ literals as output data items in write or print statements.

1 Like

@dmikushin, as Peter mentions, you can fix Steve’s program as follows to get it to compile:

integer :: j
j = int(z'0ff')
print *, j
end

Thank you all for sharing this!

Sorry for not sharing a usecase. Actually, I’m not sure it is a solution for me, because my usecase is

integer*4 ix, iexp, imant
...
if (iand(ix,z'80000000').eq.0) then
...

If I try to cast hex literal to integer, then z'80000000' will overflow.

You could use BTEST() here and it would actually be clearer code.