[cfe-dev] Getting information from MemRegion

Jordy Rose jediknil at belkadan.com
Tue Jun 7 13:37:57 PDT 2011


Unfortunately, the analyzer runs well after the preprocessor does, so while you could probably reconstruct some of this information, it's probably more trouble than it's worth. You also won't necessarily be able to handle cases like

lock(*foo);

which the static analyzer can track (at least in theory). On the other hand, the simple example you gave *should* work anyway; unless lockR is already NULL, it should be a VarRegion whether or not it passes through a macro.

As a debugging aid, you can use MemRegion::dump() to print a description of the region. If you're printing for diagnostics, there are a few examples of "SummarizeRegion" methods among the checkers (which should probably be unified in the general CheckerHelpers.h file at some point). And to actually track data, you probably want to look at the existing PthreadLockChecker, which just associates 'locked' or 'unlocked' states with regions. (Think about 'locks[3]' or 'criticalData->lock', which would have other types of MemRegions.)

But I guess I don't know your real goals. Still, I hope that was helpful.

Jordy


On Jun 6, 2011, at 21:56, Rui Paulo wrote:

> Hi,
> 
> I was using this code to get the variable name from the MemRegion, but it fails when we mix complicated pre-processor macros:
> 
>    const VarRegion *lockVR = dyn_cast_or_null<VarRegion>(lockR);
>    const VarDecl *lockVD;
>    if (lockVR)
>      lockVD = lockVR->getDecl();
>    else
>      lockVD = NULL;
> 
> Then I would use lockVD->getName(), but for complicated macros, lockVR is null.
> 
> What I want to accomplish here is to just print the variable name as it is in the code (not how the macro expands the variable), so we could have:
> 
> #define lock(_mtx) pthread_mutex_lock((_mtx))
> 
> lock(foo);
> 
> At this point, I want to print 'foo'. Seems like I'm missing something because this doesn't work on all cases.
> 
> Any ideas?
> 
> Thanks,
> --
> Rui Paulo
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list