[llvm-bugs] [Bug 25788] New: IR parsing of floating-point constants is locale-dependent

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 9 04:35:47 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25788

            Bug ID: 25788
           Summary: IR parsing of floating-point constants is
                    locale-dependent
           Product: libraries
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM assembly language parser
          Assignee: unassignedbugs at nondot.org
          Reporter: pitrou at free.fr
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Parsing of floating-point constants in decimal notation is locale-dependent.
With a locale other than C, a bogus value may be emitted.  This was observed
with LLVM 3.6 but inspection of trunk suggests the issue hasn't been corrected,
as it seems due to the use of std::atof() in lib/AsmParser/LLLexer.cpp.

Not only atof() is locale-dependent, but it's quite lenient. So if for instance
you pass it "1.23e+01" and the current locale has the comma (",") as decimal
separator, atof() simply ignores the invalid trailing characters and returns
1.0.

I have a small reproducer using the llvmlite bindings below (I don't seem to be
able to reproduce using the LLVM command-line tools, perhaps because they force
the locale to "C"). It parses the IR and prints out the IR of the parsed
module:

```
import locale

import llvmlite.binding as llvm

ir = """
    define double @func()
    {
        ret double 1.23e+01
    }
    """

locale.setlocale(locale.LC_ALL, ("fr_FR", "UTF-8"))

llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()

mod = llvm.parse_assembly(ir)
print(mod)  # => the printed assembly returns 1.0, not 12.3...
```

Probably a similar reproducer can be written using the C++ API.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151209/2c238c76/attachment.html>


More information about the llvm-bugs mailing list