[LLVMbugs] [Bug 15968] New: constexpr code unnecessarily generated and called
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sat May 11 13:48:11 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=15968
Bug ID: 15968
Summary: constexpr code unnecessarily generated and called
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: hhinnant at apple.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 10497
--> http://llvm.org/bugs/attachment.cgi?id=10497&action=edit
date.cpp
I've been working on a constexpr date class that validates its input. If all
of the input is compile-time information, the validation should happen at
compile time.
The enclosed file ends with:
int
main()
{
constexpr ymd_date ymd(year(2013), month(5), day(11));
return ymd.year();
}
Using tip-of-trunk clang, and -O3, the generated assembly for main is:
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main: ## @main
.cfi_startproc
## BB#0: ## %entry
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
movl $2013, %edi ## imm = 0x7DD
movl $5, %esi
movl $11, %edx
callq __ZN8ymd_date16check_invariantsE4year5month3day
movl $2013, %eax ## imm = 0x7DD
popq %rbp
ret
.cfi_endproc
However the compiler should be able to deduce that the call to
__ZN8ymd_date16check_invariantsE4year5month3day is unnecessary because:
1. It is constexpr.
2. It is called in the process of constructing a constexpr.
3. It compiled.
Thus it can't possibly have any run time impact. What I'm looking for is:
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main: ## @main
.cfi_startproc
## BB#0: ## %entry
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
movl $2013, %eax ## imm = 0x7DD
popq %rbp
ret
.cfi_endproc
Which is *all* that gets generated if I change the enclosure to:
constexpr ymd_date ymd(year(2013), month(5), day(11));
int
main()
{
return ymd.year();
}
In the example the programmer can quickly loose track of what input needs to be
validated and which doesn't (because it is compile-time information). And this
seems to me to be one of the things that constexpr could do well.
--
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/20130511/a03b2e9b/attachment.html>
More information about the llvm-bugs
mailing list