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

[llvm-gcc] volatile lost in struct copy #1724

Closed
sunfishcode opened this issue Apr 24, 2007 · 4 comments
Closed

[llvm-gcc] volatile lost in struct copy #1724

sunfishcode opened this issue Apr 24, 2007 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla llvm-tools All llvm tools that do not have corresponding tag miscompilation

Comments

@sunfishcode
Copy link
Member

Bugzilla Link 1352
Resolution FIXED
Resolved on Mar 06, 2010 14:00
Version 1.9
OS All

Extended Description

I typed this into the online demo:

struct foo {
int x;
};

void copy(volatile struct foo *p, struct foo *q)
{
*p = *q;
}

It produced this:

void %copy(%struct.foo* %p, %struct.foo* %q) {
entry:
%tmp2 = getelementptr %struct.foo* %q, int 0, uint 0 ; <int*> [#uses=1]
%tmp = load int* %tmp2 ; [#uses=1]
%tmp4 = getelementptr %struct.foo* %p, int 0, uint 0 ; <int*> [#uses=1]
store int %tmp, int* %tmp4
ret void
}

The store should be volatile.

@sunfishcode
Copy link
Member Author

assigned to @lattner

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 24, 2007

The assignment happens in this bit of TreeToLLVM::EmitMODIFY_EXPR,
with isVolatile=true and DestLoc=0:

// Non-bitfield aggregate value.
Emit(TREE_OPERAND(exp, 1), LV.Ptr); <== the assignment
if (DestLoc)
  EmitAggregateCopy(DestLoc, LV.Ptr, TREE_TYPE(exp), isVolatile, false);
return 0;

And indeed nothing marks the store as volatile.

@lattner
Copy link
Collaborator

lattner commented Apr 25, 2007

Verified that this is broken on mainline, investigating.

@lattner
Copy link
Collaborator

lattner commented Apr 25, 2007

Fixed. Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070423/048374.html

Testcase here: test/CFrontend/2007-04-24-VolatileStructCopy.c

Thanks!

-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 llvm-tools All llvm tools that do not have corresponding tag miscompilation
Projects
None yet
Development

No branches or pull requests

3 participants