[llvm-bugs] [Bug 48925] New: Always_inline / __forceinline should override dllimport inline function suppression

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 28 13:02:43 PST 2021


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

            Bug ID: 48925
           Summary: Always_inline / __forceinline should override
                    dllimport inline function suppression
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rnk at google.com
                CC: eric at efcs.ca, hans at chromium.org,
                    llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Consider:

$ cat t.cpp 
int notImported();
int __forceinline __declspec(dllimport) foo() { return notImported(); }
int bar() { return foo(); }

$ clang -S t.cpp  -o - --target=x86_64-windows-msvc
...
# %bb.0:                                # %entry
        subq    $40, %rsp
        .seh_stackalloc 40
        .seh_endprologue
        callq   *"__imp_?foo@@YAHXZ"(%rip)
        nop
        addq    $40, %rsp
        retq
        .seh_endproc
...


Clang doesn't honor the __forceinline attribute here because the dllimport
function refers to something that is not also imported. This logic lives here:
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CodeGenModule.cpp#L3035
  if (F->hasAttr<DLLImportAttr>()) {
    // Check whether it would be safe to inline this dllimport function.
    DLLImportFunctionVisitor Visitor;
    Visitor.TraverseFunctionDecl(const_cast<FunctionDecl*>(F));
    if (!Visitor.SafeToInline)
      return false;

It seems reasonable to power down this safety check when the user has an
explicit attribute. MSVC will inline when optimizations are enabled, but not at
-Od, so this should be OK:
https://gcc.godbolt.org/z/GYTKhM

This is related to https://crbug.com/1090975#c10 and the FIXME here
http://github.com/llvm/llvm-project/commit/411210838d762303027f7ac8ddc12427d774b170.

-- 
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/20210128/b44acdf7/attachment.html>


More information about the llvm-bugs mailing list