Skip to content

Commit

Permalink
filtering GNU C attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Bernauer committed Nov 21, 2012
1 parent 43d01f4 commit a14bb05
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
13 changes: 11 additions & 2 deletions ocram/src/Ocram/Analysis/Filter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Language.C.Syntax.AST
import Ocram.Analysis.CallGraph (start_functions, is_critical)
import Ocram.Analysis.Fgl (find_loop, edge_label)
import Ocram.Analysis.Types (CallGraph(..), Label(lblName))
import Ocram.Names (ecPrefix)
import Ocram.Names (ecPrefix, blockingAttr, startAttr)
import Ocram.Query (is_start_function, is_blocking_function, function_parameters_cd, return_type_fd, function_parameters_fd)
import Ocram.Symbols (symbol)
import Ocram.Text (OcramError, new_error)
Expand All @@ -32,6 +32,7 @@ data ErrorCode = -- {{{2
| CaseRange
| CriticalRecursion
| Ellipses
| GnucAttribute
| GotoPtr
| IllFormedSwitch
| MainFunction
Expand Down Expand Up @@ -63,6 +64,8 @@ errorText CriticalRecursion =
"recursion of critical functions"
errorText Ellipses =
"No ellipses for critical functions"
errorText GnucAttribute =
"__attribute__ is a GNU extension and is only allowed to declare thread start functions and blocking functions"
errorText GotoPtr =
"Computed gotos are not part of C99 and are thus not supported"
errorText IllFormedSwitch =
Expand Down Expand Up @@ -106,7 +109,7 @@ newError code extraWhat where_ =


global_constraints :: CTranslUnit -> Either [OcramError] () -- {{{1
global_constraints ast = failOrPass $ everything (++) (mkQ [] scanExtDecl `extQ` scanBlockItem `extQ` scanStorageSpec `extQ` scanIdent) ast
global_constraints ast = failOrPass $ everything (++) (mkQ [] scanExtDecl `extQ` scanBlockItem `extQ` scanStorageSpec `extQ` scanIdent `extQ` scanAttribute) ast
where
scanExtDecl :: CExtDecl -> [OcramError]
scanExtDecl (CDeclExt (CDecl _ ds ni))
Expand Down Expand Up @@ -134,6 +137,12 @@ global_constraints ast = failOrPass $ everything (++) (mkQ [] scanExtDecl `extQ`
[newError ReservedPrefix Nothing (Just (nodeInfo ident))]
| otherwise = []

scanAttribute :: CAttribute NodeInfo -> [OcramError]
scanAttribute (CAttr (Ident name _ _) _ ni)
| name `elem` [blockingAttr, startAttr] = []
| otherwise =
[newError GnucAttribute Nothing (Just ni)]

critical_constraints :: CTranslUnit -> CallGraph -> Either [OcramError] () -- {{{1
critical_constraints ast cg = failOrPass $
checkFunctionPointer cg ast
Expand Down
17 changes: 16 additions & 1 deletion ocram/src/Ocram/Analysis/Filter/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ test_global_constraints = enumTestGroup "global_constraints" $ map runTest [
block(ec_j);
}
|], replicate 7 ReservedPrefix)
, -- 07 - function attributes {{{2
([paste|
__attribute__((tc_api)) void block(int i);

int square(int n) __attribute__((const));

void c() __attribute__((noreturn));
void c() {
block(square(23));
}

__attribute__((tc_thread)) void start() {
c();
}
|], [GnucAttribute, GnucAttribute])

-- end {{{2
]
Expand Down Expand Up @@ -290,9 +305,9 @@ test_critical_constraints = enumTestGroup "critical_constraints" $ map runTest [

__attribute__((tc_thread)) void start(int i) {
block();
return 0;
}
|], [StartFunctionSignature])

-- end {{{2
]
where
Expand Down

0 comments on commit a14bb05

Please sign in to comment.