Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
llvm-epi-0.8
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Roger Ferrer
llvm-epi-0.8
Commits
30efa2ee
Commit
30efa2ee
authored
17 years ago
by
Devang Patel
Browse files
Options
Downloads
Patches
Plain Diff
Handle simple struct member expr.
llvm-svn: 43258
parent
e670dbb9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
clang/CodeGen/CGExpr.cpp
+31
-0
31 additions, 0 deletions
clang/CodeGen/CGExpr.cpp
clang/test/CodeGen/struct.c
+39
-0
39 additions, 0 deletions
clang/test/CodeGen/struct.c
with
70 additions
and
0 deletions
clang/CodeGen/CGExpr.cpp
+
31
−
0
View file @
30efa2ee
...
@@ -101,6 +101,7 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
...
@@ -101,6 +101,7 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
return
EmitArraySubscriptExpr
(
cast
<
ArraySubscriptExpr
>
(
E
));
return
EmitArraySubscriptExpr
(
cast
<
ArraySubscriptExpr
>
(
E
));
case
Expr
::
OCUVectorElementExprClass
:
case
Expr
::
OCUVectorElementExprClass
:
return
EmitOCUVectorElementExpr
(
cast
<
OCUVectorElementExpr
>
(
E
));
return
EmitOCUVectorElementExpr
(
cast
<
OCUVectorElementExpr
>
(
E
));
case
Expr
::
MemberExprClass
:
return
EmitMemberExpr
(
cast
<
MemberExpr
>
(
E
));
}
}
}
}
...
@@ -381,6 +382,36 @@ EmitOCUVectorElementExpr(const OCUVectorElementExpr *E) {
...
@@ -381,6 +382,36 @@ EmitOCUVectorElementExpr(const OCUVectorElementExpr *E) {
E
->
getEncodedElementAccess
());
E
->
getEncodedElementAccess
());
}
}
LValue
CodeGenFunction
::
EmitMemberExpr
(
const
MemberExpr
*
E
)
{
// FIXME: Handle union members.
if
(
E
->
getBase
()
->
getType
()
->
getAsUnionType
())
{
fprintf
(
stderr
,
"Unimplemented lvalue expr!
\n
"
);
E
->
dump
(
getContext
().
SourceMgr
);
llvm
::
Type
*
Ty
=
llvm
::
PointerType
::
get
(
ConvertType
(
E
->
getType
()));
return
LValue
::
MakeAddr
(
llvm
::
UndefValue
::
get
(
Ty
));
}
LValue
BaseLV
=
EmitLValue
(
E
->
getBase
());
llvm
::
Value
*
BaseValue
=
BaseLV
.
getAddress
();
FieldDecl
*
Field
=
E
->
getMemberDecl
();
unsigned
idx
=
CGM
.
getTypes
().
getLLVMFieldNo
(
Field
);
llvm
::
Value
*
Idxs
[
2
]
=
{
llvm
::
Constant
::
getNullValue
(
llvm
::
Type
::
Int32Ty
),
llvm
::
ConstantInt
::
get
(
llvm
::
Type
::
Int32Ty
,
idx
)
};
if
(
E
->
isArrow
())
{
QualType
PTy
=
cast
<
PointerType
>
(
E
->
getBase
()
->
getType
())
->
getPointeeType
();
BaseValue
=
Builder
.
CreateBitCast
(
BaseValue
,
llvm
::
PointerType
::
get
(
ConvertType
(
PTy
)),
"tmp"
);
}
return
LValue
::
MakeAddr
(
Builder
.
CreateGEP
(
BaseValue
,
Idxs
,
Idxs
+
2
,
"tmp"
));
// FIXME: If record field does not have one to one match with llvm::StructType
// field then apply appropriate masks to select only member field bits.
}
//===--------------------------------------------------------------------===//
//===--------------------------------------------------------------------===//
// Expression Emission
// Expression Emission
//===--------------------------------------------------------------------===//
//===--------------------------------------------------------------------===//
...
...
This diff is collapsed.
Click to expand it.
clang/test/CodeGen/struct.c
0 → 100644
+
39
−
0
View file @
30efa2ee
// RUN: clang %s -emit-llvm
struct
{
int
x
;
int
y
;
}
point
;
void
fn1
()
{
point
.
x
=
42
;
}
/* Nested member */
struct
{
struct
{
int
a
;
int
b
;
}
p1
;
}
point2
;
void
fn2
()
{
point2
.
p1
.
a
=
42
;
}
/* Indirect reference */
typedef
struct
__sf
{
unsigned
char
*
c
;
short
flags
;
}
F
;
typedef
struct
__sf2
{
F
*
ff
;
}
F2
;
int
fn3
(
F2
*
c
)
{
if
(
c
->
ff
->
c
>=
0
)
return
1
;
else
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment