[LLVMbugs] [Bug 19572] New: __is_trivial() gives wrong value when Clang generates code from AST file
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sat Apr 26 15:16:46 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=19572
Bug ID: 19572
Summary: __is_trivial() gives wrong value when Clang generates
code from AST file
Product: clang
Version: 3.4
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: wluo at coverity.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 12448
--> http://llvm.org/bugs/attachment.cgi?id=12448&action=edit
A standalone reproducer.
I've attached a small standalone reproducer.
Clang 3.2 compiles it with no issue, but Clang 3.4 triggers the static_assert.
The problem exists only if I use -emit-ast and then compile from AST. If I skip
the -emit-ast step, things appear to work.
=== Clang 3.2 ===
$ ../clang32/bin/clang -c -std=c++11 test.cpp
$ ../clang32/bin/clang -emit-ast -std=c++11 test.cpp
$ ../clang32/bin/clang -c -std=c++11 test.ast
=== Clang 3.4 ===
$ ../clang34/bin/clang -c -std=c++11 test.cpp
$ ../clang34/bin/clang -c -std=c++11 -emit-ast test.cpp
$ ../clang34/bin/clang -c -std=c++11 test.ast
/home/wluo/space/test.cpp:21:5: error: static_assert failed "FOO"
static_assert(!__is_trivial(_ValueType), "FOO");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~
/home/wluo/space/test.cpp:27:5: note: in instantiation of function template
specialization
'func<struct Data<const int> *>' requested here
func(table_start);
^
1 error generated.
=== Suggested fix ===
In Clang 3.2, QualType::isTrivialType() relies on
ClassDecl->hasTrivialDefaultConstructor(), but in Clang 3.4 it uses
!ClassDecl->hasNonTrivialDefaultConstructor().
It seems ClassDecl->hasNonTrivialDefaultConstructor() is returning false in
this case, which I don't think is correct. Data<const int> has a user-provided
default constructor, and according to C++ [class.ctor] one of the requirements
for the default trivial constructor is that it isn't user-provided.
The following change seems to fix the issue:
--- a/llvm-3.4/tools/clang/lib/AST/Type.cpp
+++ b/llvm-3.4/tools/clang/lib/AST/Type.cpp
@@ -1064,9 +1064,15 @@ bool QualType::isTrivialType(ASTContext &Context) const
{
// A trivial class is a class that has a default constructor,
// has no non-trivial default constructors, and is trivially
// copyable.
+#if 1
+ // See BZ xxxxx comment x for why we don't want to use
+ // hasNonTrivialDefaultConstructor().
+ return ClassDecl->isTrivial();
+#else
return ClassDecl->hasDefaultConstructor() &&
!ClassDecl->hasNonTrivialDefaultConstructor() &&
ClassDecl->isTriviallyCopyable();
+#endif
}
return true;
--
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/20140426/ea3bd213/attachment.html>
More information about the llvm-bugs
mailing list