Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADT/SmallVector.h violates aliasing rules #1269

Closed
nlewycky opened this issue Sep 6, 2006 · 4 comments
Closed

ADT/SmallVector.h violates aliasing rules #1269

nlewycky opened this issue Sep 6, 2006 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla code-cleanup llvm:core

Comments

@nlewycky
Copy link
Contributor

nlewycky commented Sep 6, 2006

Bugzilla Link 897
Resolution FIXED
Resolved on Feb 22, 2010 12:55
Version 1.8
OS All

Extended Description

gcc 4.1.2 emits the following warning on SmallVector:

llvm/include/llvm/ADT/SmallVector.h:46: warning: dereferencing type-punned
pointer will break strict-aliasing rules

This appears to be due to the use of a union:

template
class SmallVectorImpl {
T *Begin, *End, *Capacity;

// Allocate raw space for N elements of type T. If T has a ctor or dtor, we
// don't want it to be automatically run, so we need to represent the space as
// something else. An array of char would work great, but might not be
// aligned sufficiently. Instead, we either use GCC extensions, or some
// number of union instances for the space, which guarantee maximal alignment.
protected:
union U {
double D;
long double LD;
long long L;
void P;
} FirstEl;
// Space after 'FirstEl' is clobbered, do not add any instance vars after it.
public:
// Default ctor - Initialize to empty.
SmallVectorImpl(unsigned N)
: Begin((T
)&FirstEl), End((T*)&FirstEl), Capacity((T*)&FirstEl+N) {
}

Line 46 being the one with where Begin, End and Capacity are being assigned. The
trouble is that you aren't allowed to put a "T" in the union anyways (otherwise,
that would be a neat hack to preserve the type without going through the
constructor).

@nlewycky
Copy link
Contributor Author

nlewycky commented Sep 6, 2006

assigned to @lattner

@lattner
Copy link
Collaborator

lattner commented Oct 8, 2006

test patch
Please try this patch. If it works (silences the warnings), I'll commit it.
Thanks.

-Chris

@nlewycky
Copy link
Contributor Author

nlewycky commented Oct 8, 2006

Patch works for me.

@lattner
Copy link
Collaborator

lattner commented Oct 9, 2006

Nicholas, thanks for verifying.

Fixed, patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061002/038404.html

-Chris

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla code-cleanup llvm:core
Projects
None yet
Development

No branches or pull requests

2 participants