[LLVMbugs] [Bug 21178] New: clang crashes when building with "__naked" function attribute

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Oct 6 15:10:18 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=21178

            Bug ID: 21178
           Summary: clang crashes when building with "__naked" function
                    attribute
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: viniciustinti at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 13151
  --> http://llvm.org/bugs/attachment.cgi?id=13151&action=edit
Reduced test case

Clang is not able to build the following code:

/*
 * clang-3.6 -cc1 -triple armv7-none-linux-gnueabi -S -O0 reduce.c
 */
#define __naked __attribute__((naked))

struct firmware_ops {
    int (*prepare_idle)(void);
};

extern const struct firmware_ops *firmware_ops;

static void register_firmware_ops(const struct firmware_ops *ops)
{
    firmware_ops = ops;
}

static void __naked tf_generic_smc(unsigned int type)
{
    asm volatile(
        ".arch_extension    sec\n\t"
        :
        : "r" (type)
        : "memory");
}

static int tf_prepare_idle(void)
{
    tf_generic_smc(0);
    return 0;
}

static const struct firmware_ops trusted_foundations_ops = {
    .prepare_idle = tf_prepare_idle,
};

void of_register_trusted_foundations(void)
{
    register_firmware_ops(&trusted_foundations_ops);
}
/* end */

When compiling it gives the following crash. Using Clang's debug version it
fails at the assertion below

/* crash */
0  clang-3.6       0x0000000000f3db95 llvm::sys::PrintStackTrace(_IO_FILE*) +
37
1  clang-3.6       0x0000000000f3df7b
2  libpthread.so.0 0x00002b267c8f9340
3  clang-3.6       0x0000000001379ee1
clang::CodeGen::CodeGenFunction::GetAddrOfBlockDecl(clang::VarDecl const*,
bool) + 33
4  clang-3.6       0x00000000013b6076
clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(clang::DeclRefExpr const*) +
2534
5  clang-3.6       0x00000000013ae0f9
clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*) + 441
6  clang-3.6       0x00000000013b3a63
clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*,
clang::CodeGen::CodeGenFunction::TypeCheckKind) + 99
7  clang-3.6       0x00000000013e0142
8  clang-3.6       0x00000000013e18b9
9  clang-3.6       0x00000000013da45c
10 clang-3.6       0x00000000013d257c
clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) + 76
11 clang-3.6       0x00000000012f750f
clang::CodeGen::CodeGenFunction::EmitAsmInput(clang::TargetInfo::ConstraintInfo
const&, clang::Expr const*, std::string&) + 303
12 clang-3.6       0x00000000012f2d1d
clang::CodeGen::CodeGenFunction::EmitAsmStmt(clang::AsmStmt const&) + 7869
13 clang-3.6       0x00000000012eded3
clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) + 451
14 clang-3.6       0x00000000012f5d5b
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot) + 91
15 clang-3.6       0x0000000001302554
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&) + 1332
16 clang-3.6       0x000000000130f2a9
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*) + 1241
17 clang-3.6       0x000000000130c710
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*) + 336
18 clang-3.6       0x000000000130802e clang::CodeGen::CodeGenModule::Release()
+ 46
19 clang-3.6       0x00000000012c2293
20 clang-3.6       0x000000000175bc93 clang::ParseAST(clang::Sema&, bool, bool)
+ 467
21 clang-3.6       0x00000000012c13ec clang::CodeGenAction::ExecuteAction() +
76
22 clang-3.6       0x00000000010a5969 clang::FrontendAction::Execute() + 57
23 clang-3.6       0x0000000001079483
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 803
24 clang-3.6       0x00000000011135c5
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3141
25 clang-3.6       0x000000000067aa7e cc1_main(llvm::ArrayRef<char const*>,
char const*, void*) + 590
26 clang-3.6       0x0000000000679e20 main + 11536
27 libc.so.6       0x00002b267d561ec5 __libc_start_main + 245
28 clang-3.6       0x000000000067700b

/* assertion */
clang-3.6: /src/clang/lib/CodeGen/CGExpr.cpp:1956: clang::CodeGen::LValue
clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(const clang::DeclRefExpr *):
Assertion `isa<BlockDecl>(CurCodeDecl) && E->refersToEnclosingLocal()' failed.

-- 
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/20141006/23e03cd6/attachment.html>


More information about the llvm-bugs mailing list